The final is a keyword. This is similar to const keyword in other languages.
The final is a keyword. This is similar to const keyword in other languages.The
final is a keyword. This is similar to const
keyword in other languages.
This keyword may not be used as identifiers i.e. you cannot declare a variable
or class with this name in your Java program.
In
the Java programming language, the keyword "final" is used with
different entity, which makes it unchangeable later. It is a modifier that
indicates that a class cannot be extended, a variable cannot be changed, and a
method cannot be overridden. We can have final methods, final classes, final
data members, final local variables and final parameters.
final
keyword cannot be modified by the program, once it has been initialized. It
can only be assigned to once.
public final double radius = 126.45; public final int PI = 3.145; |
public class MyFinalClass { public final void myFinalMethod()
{
???...
} |
public
final class MyFinalClass { ???.. .} |
final Fields
The
fields can also be declared as final
. This is not the same thing
as declaring a method or class to be final
. When
a field is declared final
,
it is a constant, which cannot be changed. It can be set once.
Ads