Skip to main content

Difference between final, finally, finalize


Difference between final, finally, and finalize:
Final:
• The final is the modifier applicable for class, methods, and variables.
• If a class declared as the final then child class creation is not possible.
• If a method declared as the final then overriding of that method is not possible.
• If a variable declared as the final then reassignment is not possible.
Finally:
• It is the block always associated with try-catch to maintain clean up code which should be executed always irrespective of whether exception raised or not raised and whether handled or not handled.
Finalize:
• It is a method which should be called by garbage collector always just before destroying an object to perform cleanup activities.
Note:
• To maintain clean up code faunally block is recommended over the finalize() method because we can’t expert the exact behavior of GC.

Comments

Popular posts from this blog

Core Java

Content 1 - Language fundamental   Identifier Reserved words Data types Literals Arrays Types of variables Var arg method Main method Java coding standards 2 -  Declaration and Access Modifiers Java source file structure Class modifiers Member modifiers Interfaces 3 - Exception Handling Introduction Runtime stack mechanism Default exception handling in java Exception hierarchy Customized exception handling by try-catch  Control flow in try-catch Methods to print exception information Try with multiple catch blocks Finally Difference between final, finally, finalize Control flow in try-catch-finally Control flow in nested try-catch-finally Various possible combinations of try-catch-finally throw keyword throws keyword Exception handling keywords summary Various possible compile-time errors in exception handling Customized exceptions Top-10 exceptions  4 - String Concept of String Immutable String String Comparison String Conca