Amazon Interview Question
Software Engineer / DevelopersI knew the answer - i just wanted others to think about it. my answer was:
1. the deconstructor is a C or C++ function for closing the resources - i.e. garbage collection. Java does not use a deconstructor but uses garbage collection to handle closing resources. In java you request- not force or push - this mechanism through calling system.gc().
In the deconstrctor() method. We can close all resources used by the current object. Invoke the deconstrctor() methods on the objects referenced by the current object, if the referenced objects also have deconstrctor() methods. Then put the referenced objects to null.
- Yang Yang March 03, 2010Java uses Garbage collections mechanism to handle this. In Java we can use System.gc() or Runtime.getRuntime().gc() to runs the garbage collector. JVM hold references to all objects created in JVM. The garbage collector will collect those objects which are not referenced by any objects. The collection is asynchronized.