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

Explain try and catch keywords in java?

623


What are peerless components?

626


How do you calculate square roots?

581


Is zero a positive integer?

537


What is passing parameters in java?

529






what is meant by HQL?

645


What is variable in java?

529


Are the imports checked for validity at compile time? Will the code containing an import such as java.lang.abcd compile?

601


Why is string class considered immutable?

598


What is difference between identifier and variable?

477


How can we find the sum of two linked lists using stack in java?

574


What are the 6 boolean operators?

556


Can static methods be inherited?

537


What is an abstract class and what is it’s purpose?

539


What is the difference between static method and instance method in Java?

574