Why do we need a finalize() method when Garbage Collection is there ?

Why do we need a finalize() method when Garbage Collection is there ?

Before performing the garbage collection the JVM called the finalize() method to cleanup the resources such as closing the file or socket connection etc.


 The finalize() method is declared in the java.lang.Object class.

 When you implement the finalize method, you are actually overriding it from the Object class.Your finalize() method must be declared as follows:

 protected void finalize () throws throwable{//some cleanup code here}


By:Jalees
Date:2011-01-09 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher