What is the final variable and final method ?
All methods and variable can be overriding by default in sub-classes if we wish to prevent the sub-classes from overriding the member of the super class we can declare then, as final using the keyword final as modifier.
Example :-
final int size = 20;
final void add()
{ ————————-
————————–
}
A making a methods a final answer that the functionality define in any way. Similarly the value of final variable can never be change the like class variable and they do not take any space on individual object of the class.
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment