Garbage collection system allows programmer to destroy object x - Java

Q.  Which of the following allows the programmer to destroy an object x? (Java)
- Published on 26 Jun 15

a. x.delete()
b. x.finalize()
c. Runtime.getRuntime().gc()
d. Only the garbage collection system can destroy an object.

ANSWER: Only the garbage collection system can destroy an object.
 
When an object is no longer referenced, it can be reclaimed by the garbage collector. If an object declares a finalizer, it is executed before the object is reclaimed to give the object a last chance to clean up resources that would not otherwise be released. When a class is no longer needed, it may be unloaded.

Post your comment / Share knowledge


Enter the code shown above:
 
(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)