Can anyone explain me the following sentence? I can't follow the explanation to the answer:
When the following method reaches line 8, how many of the
String objects created in line 5 are eligible for garbage collection? Assume that the System.out object is not keeping a reference.
1.public void countDown()
2.{
3. for( int i = 10 ; i >= 0 ; i-- )
4.{
5.String tmp = Integer.toString( i );
6.System.out.println( tmp );
7. }
8.System.out.println("BOOM!");
9.}
ANSWER:
10
EXPLANATION:
Because only the last String object of the 11 created still has a reference. Because even though the tmp variable is out of scope in line 8, the local variable still has a reference.