Searching for "finalize()"

Q:

When is the finalize() called ? What is the purpose of finalization ?

Answer

The finalize method is called by the garbage collector, just before releasing the object’s memory. It is normally advised to release resources held by the object inside the finalize method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

Q:

why overriding finalize() method?

Answer

If constructor opens the file 


finalize() method closes that file.


 


If constructor opens the connection 


finalize() method closes that connection.


 


To perform finalization operation we must overriding finalize method.

Report Error

View answer Workspace Report Error Discuss

Subject: Java

Q:

How is final different from finally and finalize()?

Answer final is a modifier which can be applied to a class or a method or a variable. final class can't be inherited, final method can't be overridden and final variable can't be changed.

finally is an exception handling code section which gets executed whether an exception is raised or not by the try block code segment.

finalize() is a method of Object class which will be executed by the JVM just before garbage collecting object to give a final chance for resource releasing activity.
Report Error

View answer Workspace Report Error Discuss

Subject: Java