0% found this document useful (0 votes)
53 views1 page

What Is Final, Finally and Finalize?: Answer

Final is a keyword that makes a variable or class immutable and prevents overriding of methods. Finally is a block that always executes after a try block to ensure cleanup code runs. Finalize is a method called by the runtime system before garbage collection to allow an object to perform cleanup.

Uploaded by

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

What Is Final, Finally and Finalize?: Answer

Final is a keyword that makes a variable or class immutable and prevents overriding of methods. Finally is a block that always executes after a try block to ensure cleanup code runs. Finalize is a method called by the runtime system before garbage collection to allow an object to perform cleanup.

Uploaded by

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

What is final, finally and finalize?

Answer:
final:
final is a keyword. The variable decleared as final should be
initialized only once and cannot be changed. Java classes
declared as final cannot be extended. Methods declared as final
cannot be overridden.

finally:
finally is a block. The finally block always executes when the
try block exits. This ensures that the finally block is executed
even if an unexpected exception occurs. But finally is useful for
more than just exception handling - it allows the programmer to
avoid having cleanup code accidentally bypassed by a return,
continue, or break. Putting cleanup code in a finally block is
always a good practice, even when no exceptions are anticipated.

finalize:
finalize is a method. Before an object is garbage collected, the
runtime system calls its finalize() method. You can write system
resources release code in finalize() method before getting garbage
collected.

You might also like