final :
- final is a modifier applicable for classes, methods and variables. If a class declared as final then we cant extend that class. i.e we cant create child class for that class.
- If a method declared as final then we can't override that method in the child class.
- If a variable declared as final then it will become constant and we can't perform re-assignment for that variables.
finally :
- finally is a block always associated with try-catch to maintain cleanup code.
{
//risky code
}
catch( Exception e)
{
//handling code
}
finally
{
//cleanup code
}
finalize() :
- finalize() is a method which is always invoked by garbage collector just before destroying an object to perform cleanup activities.
Note : Both finally and finalize() are meant for cleanup activity only but,
- the finally block is responsible for cleanup activity related to try block i.e whatever resources are opened in try block will be closed by finally block.
- The finalize() method is associated with the object i.e all the resources related to object will be closed by finalize() method. The garbage collector is responsible for calling finalize() method just before destroying an object.
No comments:
Post a Comment