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

Define linked list and its features with signature?

538


Is an integer an object?

515


What is empty string literal in java?

560


1.IN CASE OF DYNAMIC METHOD DISPATCH WHY WE USE REFERENCE VARIABLE,WE CAN USE THE DIFFERENT DEFINED OBJECT DIRECTLY TO ACCESS THE DATA MEMBER AND MEMBER FUNCTION OF THAT RESPECTIVE CLASS?WHAT IS THE MAIN FUNCTION OF "REFERENCE VARIABLE" HERE?

3790


How can you read an integer value from the keyword when the application is runtime in java? example?

620






What is a key in java?

503


What happens if main method is not static?

495


What is a Transient Object?

636


List some oops concepts in java?

581


How do you write a scanner class in java?

566


What is an association?

549


What is the method to expand and collapse nodes in a jtree?

610


What is an i/o filter?

565


How do you clear a method in java?

539


When we serialize an object does the serialization mechanism saves its references too?

508