• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Final keyword

 
Ja King
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to know the details about the final keyword...

What is the use of preventing a method from overriding by using final keyword...
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
vijai ganesh wrote:I want to know the details about the final keyword...
What is the use of preventing a method from overriding by using final keyword...


If the method should not be overriden in sub classes (i.e: that the implementation is complete/suficient so subclasses can be satisfied with this one). In that way other parts of the application can make sure the behavior of the method in any class (when used).
 
Tekchand Prasad
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The final keyword may be applied to a class, indicating the class may not be extended (subclassed).
The final keyword may be applied to a method, indicating the method may not be overridden in any subclass.
Examples

A class may never be both abstract and final. abstract means the class must be extended, while final
means it cannot be.

A method may never be both abstract and final. abstract means the method must be overridden, while
final means it cannot be.
 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please go thru this

http://javapapers.com/core-java/explain-the-final-keyword-in-java/

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic