0% found this document useful (0 votes)
7 views4 pages

Final: Finalize

The document explains the differences between 'final', 'finally', and 'finalize()' in programming. 'Final' is a modifier that prevents class extension, method overriding, and variable reassignment. 'Finally' is a block used for cleanup in try-catch structures, while 'finalize()' is a method called by the garbage collector for object cleanup.

Uploaded by

49gmy2ckt8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Final: Finalize

The document explains the differences between 'final', 'finally', and 'finalize()' in programming. 'Final' is a modifier that prevents class extension, method overriding, and variable reassignment. 'Finally' is a block used for cleanup in try-catch structures, while 'finalize()' is a method called by the garbage collector for object cleanup.

Uploaded by

49gmy2ckt8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Final

VS

finalize
VS

finally
final
1. final is a modier applicable for classes, methods and variables.If a
class declared as final then we can't extend that class.
i.e we can't create child class for that class.

2. If a method declared as final then we can't override that method


in the child class.

3. If a variable declared as final then it will become constant and we


can't perform re-assignment for that variable.
finally
* finally is a block always associated with try
catch to maintain cleanup code.
try {
/ risky code…
}
{
catch(X 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
* finally meant for cleanup activities related to try
block. where as finalize() meant for cleanup activities
related to object.

You might also like