What is the difference between final, finally and finalize?
final: final is a keyword used to create constants and non-inheritable classes. If final is used with a variable, some value should be assigned to that variable, and that value can't be changed again. If final is used for classes, you can't extend those classes.
finally: finally is used with try...catch block. finally is a block of statements which executes nevertheless the exception occurred or not. If exception occurs execution will come to catch block, executes the necessary statements then comes to finally block. If exception doesn't occur then try block will be executed fully, then execution comes to finally block. This finally block was commonly used to cleanup any resources held.
finalize: finalize is a method which will be called before the object is garbage collected. Garbage collector will call this method once, before it reclaims the memory of the object. So, any cleanup code will be put in the finalize block.
Java Search Engine
Saturday, November 24, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment