Like This Site? 
 
RSS Feed Follow Us 

on Twitter! Be Our Fan!

final, finally and finalize() in JAVA - When to use What

Share this post!
 Vote this!

All the three keywords final, finally and finalize() plays a very important role in JAVA. Final is a keyword used for declaration of variable which cannot be edited, finally is a segment of code used for code cleanup in case of an exception whereas finalize is a method used for object cleanup before garbage collection.


Use of final, finally and finalize

Final:- It is used in the following three cases:
  1. If the final keyword is attached to a variable then the variable becomes constant i.e. its value cannot be changed in the program.
  2. If a method is marked as final then the method cannot be overridden by any other method.
  3. If a class is marked as final then this class cannot be inherited by any other class.  more...

0 comments:

Post a Comment