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 bom encoding?

801


Explain 5 io best practices?

829


What do you mean by global variable?

734


Which container method is used to cause a container to be laid out and redisplayed in java programming?

886


Why is it called buffering?

860


What are locale settings?

778


Can sleep() method causes another thread to sleep?

808


How does enum work in java?

802


Does list maintain insertion order java?

727


How do you sort in ascending order in java?

705


What is the advantage of functional interface in java 8?

793


What is difference between core java and java ee?

703


Can we catch more than one exception in single catch block?

861


What is advantage of java?

792


What is mean by encoding?

841