Thursday, 14 January 2016

Difference between final, finally and finalize in java


final -
final is a keyword.
When a variable declared as final should be initialized only once and it cannot be changed.
In case of classes, final classes cannot be extended
In case of methods, final methods cannot be overridden.


finally -
finally is a block
finally is used in exception handling, is used to place code that are important and it will be executed whether the exception is handled or not.The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs.


finalize -
finalize is a method.
Before an object is garbage collected, the run time system calls its finalize() method. That means this method used for clean up processing before object is garbage collected

No comments :

Post a Comment