what are the differences between final,finally,finalize
methods?

Answer Posted / jayakrishnan.p

final is used for making a class no-subclassable, and making
a member variable as a constant which cannot be modified.
finally is usually used to release all the resources
utilized inside the try block. All the resources present in
the finalize method will be garbage collected whenever GC is
called. Though finally and finalize seem to be for a similar
task there is an interesting difference here.This is because
the code in finally block is guaranteed of execution
irrespective of occurrence of exception, while execution of
finalize is not guarenteed.finalize method is called by the
garbage collector on an object when the garbage collector
determines that there are no more references to the object.

Is This Answer Correct ?    168 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is stack class in java?

550


Why java doesn’t support multiple inheritances?

592


A person says that he compiled a java class successfully without even having a main method in it? Is it possible?

589


Can we write any code after throw statement?

615


What mechanism does java use for memory management?

498






Can we sort set in java?

545


Explain what is Marker interface?

625


How do you clear a list in java?

606


Why declare Main() method as a static in java ?

600


What are heap memory and stack memory and what are memory tables.

519


Which sorting algorithm is in place?

542


Program to Find the second largest element in an array.

592


Why is the main method static?

610


What is the method to declare member of a class static?

539


How variables are declared?

521