Easy learning with example program codes

what is the difference between final finally and finalize in java?

final: final is a keyword in java which can be used with instance variables, local variables , methods and classes.

finally: finally block is mainly used to do clean-up task. It is always executed even when no exception occur. It will not execute only in case program exits using System.exit() or because of some fatal error cause program to abort. It is followed by either catch or try block.
Note: A try block can have one or more catch block associated with it, but only one finally block can be associates with it.

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

Java interview questions on exception handling

Please follow and like us:

Copyright © 2020 CodesJava Protection Status