Veena Pointi wrote:
Answer is Immediately after line 10.
But shouldn't the answer be after line 4?
The answer seems correct to me.
Veena Pointi wrote:
Because temp is local variable and local variables go out of scope after method exits
Veena
Indeed
Veena Pointi wrote:
becoming eligible for garbage collection.
Thanks,
Veena
This happens immediately after line 10 for the
String object instantiated on line 3 because there will no longer be any references to it then. Specifically, at the aforementioned method exit, the String reference is returned, assigned to the result String reference, printed, and after line 10 since the code no longer references the String object instantiated on line 3, then the String object instantiated on line 3 becomes eligible for garbage collection.
Does that help?