Difference between final, finally, finalize

Final : final is an access modifier which can be used with class, method and variable.
Variable : if you declared an variable with final than it will become a constant.you can not reassigned the value in final variable.
Method : if you declared a method with final  then you can not overide this method in child class.
Class : if you create a class with final then you can not extend that class.i. e we can not create a child class for final class.

finally : finally is block of which is always associated whit try..catch block and its used for code cleanup. That mean clearing the object.if some database or file operation is performed in try block then the final. Block is used for cleaing i.e closing that database, file objects.

finalize : finalize is an method which used for cleanup objects. The gaebage collector call finlize() method before destroying the object for clean up of that object.

Comments

Popular posts from this blog

Primitive Data Types in java

let - Keyword in JavaScript (Block scope)

Coding Problem 4: Smallest window containing 0, 1 and 2 [GFG - Problem Solving]