Hello folks,
What is your answer to the following question:
----------------------------------------------------------
From the following code how many objects are garbage collected?
String string1 = "Test";
String string2 = "Today";
string1 = null;
string1 = string2;
1) 1
2) 2
3) 3
4) 0
------------------------------------------------------
I ran across this question in one of the mock exams. The answer it gave is #1, with this explanation, " (string1 = string2) causes the garbage collecing of string1 because a fresh copy of string1 is created and the old one is garbage collected."
However, the question asks "how many objects are to be GC'ed?". Such question seems to implies "NOW"... And that kills me! All we know is that the old string1 is ready for GC when it is set to null.... But that does not mean "IT IS" collected.
What do you think? Isn't the question a bit ambiguous ?
Thanks,
Lam
P.S. maybe this is the case where "IS" is "NOT IS"