Hi, there's a practice paper :
http://www.javaranch.com/maha/_Mock_Exams/MindQ_s_Sun_Certified_Java_Programmer_Practice_Test.htm with the question:
36. How many objects are eligible for garbage collection once execution has reached the line labeled Line A?
where the answer is a multiple choice of 0,1,2,3 or 4
I answered 0 while the answer sheet is saying 1, i'm not sure I understand the reason.
This was my logic:
String name; //1 variable, 0 objects
String newName = "Nick"; //2 variables, 1 object(value is obtained from string pool)
newName = "Jason"; //same object now references the "Jason" literal
name = "Frieda"; //2 variables, 2 objects
String newestName = name; //3 variables, 2 objects
name = null; //3 variables(one of which is null), still 2 objects.
So I ended up with 0 objects eligible for garbage collection, where am I going wrong with this please?
[ September 05, 2006: Message edited by: Allan Morris ]