Hi Friends,
Please read a quesion from mock exam.
You have to select when object first is eligible for garbage collection?
class Riddle {
public static void main(
String[] args) {
String first, second;
String riddle;
if (args.length < 2)
return; a: first = new String(args[0]);
b: second = new String(args[1]);
c: riddle = "When is a " + first;
d: first = null;
e: riddle += " like a " + second + "?";
f: second = null;
g: System.out.println(riddle);
h: args[0] = null;
i: args[1] = null;
j:
}
}
Select the one right answer.
a. d:
b. e:
c. h:
d. i:
e. j:
The ans. given is a but I think it should be c as the object first can still be referenced by args[0].
Even after reading about GC a lot, I still fail to understnad some questions. Please help to clear this question's doubt.
Thanks
Jyotsna