Hi,
These Q r from MindQ #36 & 37
36. How many objects are eligible for garbage collection once execution has reached the 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
The ans given is b)1 but i feel it should be c)2 coz when string newName is reinitilized to "jason", the previous string "Nick" is eligible for GC and when name=null; the string "Frieda" is also eligible for GC. This means there r 2 objects eligible for GC and not 1. Anything wrong?
37. Which of the following statements about
Java's garbage collection are true?
a) The garbage collector can be invoked explicitly using a Runtime object.
b) The finalize method is always called before an object is garbage collected.
c) Any class that includes a finalize method should invoke its superclass' finalize method.
d) Garbage collection behavior is very predictable.
Ths ans is a,b,c but i feel a is not correct coz nobody can invoke a GC and one can't be sure whether GC will ever run.
Thanks
Sanjeet