Question from MindQ
36. How many objects are
eligible for garbage collection once execution has reached line labeled Line A
String name;
String newname = "Nick";
newname = "Jason";
name = "Frieda";
String newestName = name;
name = null;
//Line A
a)0
b)1
c)2
d)3
e)4
I thought that the answer should be c)2 , but the answer given is b
newname = "Nick"; becomes eligible for garbage collection once the statement newname = "Jason"; is executed and name = null;
is the second object which is eligible
So how come the answer is b) 1
Thanks,
Srini