Can somebody explain the next?:
I have a mock exam simulator and I'm not pretty sure if this question is right answered:
-----------------------------------
Here is a method which creates a number of
String objects in the course of printing a count down sequence. When the program reaches
line 8, how many of the String objects created in
line 5 are eligible for
garbage collection?. Assume that the System.out is not keeping a reference.
public void countDown()
{
for(int i = 10; i>=0; i--)
{
String tmp = Integer.toString(i);//line 5
System.out.println(tmp);
}
System.out.println("Boom!");//line 8
}
I think the answer is 11.
But my simulator states the anwser is 10. It also states only the last String object created still has a reference.
I think once outside the loop there's no more references for "tmp".
[ August 26, 2006: Message edited by: Barry Gaunt ]