I am preparing for
scjp(1.4). When I was taking up a mock
test I came across the following question on garbage collection.
Question: How many objects would be eligible for garbage collection at line number 9:
Code:
My answer to the above question was "B". But the mock exam told that my answer was wrong and it said "C" was the correct answer.
The reason that the mock exam states for this is that the last
String object still has a reference and hence it will not be eligible for garbage collection. Hence the answer 9.
But what I thought is that since the reference "s" looses its scope at line 9, i thought all the 10 objects are eligible for garbage collection.
Can some one tell me if I am right or wrong in this.
[ Jess fixed the [ code ] tags ]
[ April 23, 2003: Message edited by: Jessica Sant ]