what is finalmethod & final variable with example?

Answer Posted / pavan

final method or variable is nothing but once if we declare
as it is final the value of that variable cant be changed
and becomes const.
Example:
--------
final b=200;
Here the value of b is 200 thought the prog
class A
{
void final b=200;
}//A
class B extends class A
{
this.b=201;//Error becoz the variable b is declared as final
//Here this represents the current value i.e.,in
class B that is about variable final

Know coming to the method:
-------------------------
final Add();//similar as variable
Final method can be def as the method name can not be
re-used and at the same time it cant be overridden..
Example:
--------
class A{
final Add()
{
int a,b,c;//Here in this we are adding two int no.
c=a+b;
}
class B extends class A
{
final Add()
{
float a,b,c;//Here we are adding two float no.
c=a+b;
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is method overloading in JAVA? Why is it not present in C ?

563


Difference between comparator and comparable in java?

590


What happens to the Exception object after handling an exception?

1791


How can we use primitive data types as objects?

538


why java uses class level type casting ?

2230






What are the special characters?

513


Which collection allows duplicate values in java?

521


Is null function in java?

544


What string is utf8?

527


What is collection api?

590


What is the use of volatile in java?

575


What is anti pattern in cyber security?

500


How big is a 64 bit float?

511


How we can skip finally block of exception even if some exception occurs in the exception block in java?

498


What is pass by value?

492