Correct Answer: Garbage collector never invoked in methodA()
Explanation:
Option A is wrong. Because the reference to obj1 is stored in obj2[0]. The Object obj1 still exists on the heap and can be accessed by an active thread through the reference stored in obj2[0].
Option B is wrong. Because it is only one of the references to the object obj1, the other reference is maintained in obj2[0].
Option C is wrong. The garbage collector will not be called here because a reference to the object is being maintained and returned in obj2[0].
Discussion & Comments