Any variable either member variable or local variable (declared inside method or block) modified by final keyword is called final variable. Final variables are often declare with static keyword in java and treated as constant.
The final keyword is placing an important role in three levels.They are
syntax: final datatype variable_name=variable_value;
example: final int a=10;
Therefore final variable values can not be modified.
2. At method level
{
//body
}
Once the method is final which can not be overridden.
3. At class level
Java class with final modifier is called final class in Java. Final class is complete in nature and can not be sub-classed or inherited. Several classes in Java are final e.g. String, Integer and other wrapper classes.
syntax: final class <class_name>
{
//.................................
}
0 comments:
Post a Comment