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
How to remove the trailing spaces from a string?
In how many ways we can do synchronization in java?
What is the purpose of a volatile variable?
What is a java string?
What is the difference between Java and C++?
Explain the selection sort algorithm and state its time complexity?
Difference between character constant and string constant in java ?
What is the transient keyword?
Can we start a thread twice in java?
What does the exclamation mark mean in java?
What is heterogeneous in java?
How to write custom exception in java?
What is an immutable class? How to create an immutable class?
What are the java ide’s?
What does t in java mean?