Consider the following code:
class MyClass {/*from w w w . jav a 2s. c o m*/ } public class Main { MyClass getMyClassObject() { MyClass mc = new MyClass(); // 1 return mc; // 2 } public static void main(String[] args) { Main tc = new Main(); // 3 MyClass x = tc.getMyClassObject(); // 4 System.out.println("got myclass object"); // 5 x = new MyClass(); // 6 System.out.println("done"); // 7 } }
After what line the MyClass object created at line 1 will be eligible for garbage collection?
Select 1 option
Correct Option is : C
An object can be made eligible for garbage collection by making sure there are no references pointing to that object.
You cannot directly invoke the garbage collector.
You can suggest the JVM to perform garbage collection by calling System.gc()
;