If you declared Java variable is final, then that variable cannot re-declared that declaration for the single time.
Means that variable can be initialized only for a single time. Â If Java classes are declared final, then those Java classes cannot be further extended.
It means you cannot inherit the data from the superclass. The final keyword is used for the following purposes in Java.
- Preventing a class from being inherited by another class.
- Declaring a constant variable
- Preventing a method from being overridden.
the following syntax is used to declare the final class,Â
public final class XYZ{
Statements1;
Statements2;
Statements3;
.
.
}
the following syntax is used to declare the final variable,
public final class XYZ{
public final int PI=3.14;
public final float I=2.14F;
.
.
}
the following syntax is used to declare the final method,
public final class XYZ{
public final void display(){
.........
.........
}
.
.
}