Originally posted by eswar kumar:
how many times a finalize() method will called by the GC?
Blatant homework question! But I've a couple of minutes spare, so I'll answer anyway.
The answer is available in the API documentation for java.lang.Object and it is: -
"The finalize method is never invoked more than once by a
Java virtual machine for any given object."
This is important to anyone who has ever been tempted to "resurrect" a "dead" object via its finalize() method. That is, creating a strong reference to the object, while its finalize() method is executing, so that it is no longer eligible for GC. If, having resurrected the object in this way, the object later again becomes eligible for GC, then its finalize() method will
not be called again.