Difference Between final, finally, finalize
final is a modifier applicable for method, classes & variables.
1.final method:-
Whatever method parent class has by default available to the child class through inheritance.
If the child class is not satisfied with the parent method implementation than the child is allowed to redefine that method based on its requirement, this process is called "Overriding".
But,
If the parent class method declared as final then we can't override that method in child class. Because it's implementation is final.
2. final class:-
If a class declared as final we can't extend the functionality of that class so that we can not create the child class for that class. That's why inheritance is impossible for final classes.
3. final variable:-
If a variable declared as final then we can't perform reassignment for that variable.
finally is a block which is always associated with try catch block.
finally, is used to perform the cleanup activity.
try
{
Risky Code
}
catch(Exception e)
{
Handling Code
}
finally
{
Cleanup code
}
The specialty of finally block is it will be executed always irrespectively whether the exception has risen or not and whether we handled or not.
finalize ( ) is a method. It is always called by the garbage collector just before the destroying the object to perform the cleanup activity.
Once finalize method completes immediately garbage collector destroy that object.
Note: clean up- finally block is responsible for clean-up activity related the try catch block.
But
finalize () method is responsible to perform for clean-up activity related the object.
No comments:
Post a Comment
Be the first to comment!
Don't just read and walk away, Your Feedback Is Always Appreciated. I will try to reply to your queries as soon as time allows.
Note:
1. If your question is unrelated to this article, please use our Facebook Page.
2. Please always make use of your name in the comment box instead of anonymous so that i can respond to you through your name and don't make use of Names such as "Admin" or "ADMIN" if you want your Comment to be published.
Regards,
JavaByChetan
Back To Home