xxxxxxxxxx
Final is used to apply restrictions on class, method, and variable.
The final class can't be inherited, final method can't be overridden,
and final variable value can't be changed. Final is a keyword
xxxxxxxxxx
Final is used to apply restrictions on class, method, and variable.
The final class can't be inherited, final method can't be overridden,
and final variable value can't be changed. Final is a keyword
xxxxxxxxxx
if a variable declared as final then no class can change its value once
it is given a value.
xxxxxxxxxx
This simple explanation is to all those people who are overwhelmed by
the technical answer proveded by your mentors, google etc Have fun!!!
The key word : "final"
The final key word is used to declare a variable as constant
Can be implemented on classes, attributes methods
Example:
if i declare a variable like
{
int example = 10;
}
i can overwrite it by
{
example = 20;
}
now example is "20".
//===============================================================
final can be used to declare a class , attribute , method
as constant throught the program so that they cannot be OVERWRITTEN !!!
{
final int example = 10;
example = 20; //this will give an error.
}
xxxxxxxxxx
// Value cannot be changed:
final double PI = 3.14;
Note that the variable must be given a value when it is declared as final. final variables cannot be changed; any attempts at doing so will result in an error message.