I need your help:
The following is from Mr. Devaka's
ExamLab SCJP Simulator :
Practice Exam 1, question 42:
How many objects are eligible for the Garbage Collector, after executing the line-9 of this programm. F.Y.I: Array is an object.
1. public class Gabc{
2. Gabc ob[];
3. public Gabc(Gabc... gb){
4. ob=gb;
5. }
6. public static void main(
String args[]){
7. Gabc bc=new Gabc(new Gabc(),new Gabc());
8. bc.ob[1].ob=new Gabc[]{new Gabc(),bc.ob[0]};
9. bc.ob[0]=null;
10. System.gc();
11. }
12. public void finalize(){
13. System.out.println("-GCed-");
14. }
15. }
According to ExamLab the answer is:
A 0, means at that point no Object is eligible for the gc.
What I think is that after executing
line 8, there is one Object eligible for the gc: The Object, that was referred before by
bc.ob[1].ob - an array of length 0. So shouldn't the answer be:
B 1?
Thanks for your clarification.