Hi,
I was trying to solve questions related to Garbage Collection in Kathy Sierra
SCJP book and I found that questions relating to the topic mentioned went wrong . I appreciate if some one could analyze and tell me how to answer these kind of questions. For sample, I am providing a questions given in the book..
public class X {
1 public static void main(
String args[])
2 {
3 X x=new X();
4 X x2=m1(x);
5 X x4=new X();
6 x2=x4;
7
8 }
9
10 private static X m1(X mx) {
11 mx=new X();
12 return mx;
}
}
After line 6 how many objects are eligible for garbage collection..
A. 0
B. 1
C. 2
D. 3
E. 4
answer: B
class X2{
public X2 x;
public static void main(String args[])
{
X2 x2=new X2();
X2 x3=new X2();
x2.x=x3;
x3.x=x2;
x2=new X2();
x3=x2;//line 9
}
}
after line 9 , how many objects are eligible for garbage collection?
-Reference
SCP&D for java2 Study Guide Kathy Sierra and Bert Bates
Appreciate your time in replying
Thanks
Madhu
}
}