Exam Lab for SCJP 5 Question 19
1. class A{
2.
3. A a1;
4. A a2;
5.
6. public void finalize(){
7. System.out.println("-");
8. }
9.
10. public static void main(
String args[]){
11. A s1=new A();
12. s1.a1=new A();
13. s1.a2=s1;
14. s1.a1.a2=new A();
15. s1.a1.a2.a2=new A();
16. s1.a1.a2.a2.a1=s1.a1;
17. s1.a2.a1.a2=null;
18. System.gc();
19. }
20.
21. }
How many Objects are eligible for GC after Line 17. As mentioned in the ans I tried to draw graph which is attached with this question.
First of all is this graph correct?
Secondly if it is then am I correct then the object we are making null is shown in yellow color and Objects that are not reachable are shown by red arrow. T two objects eligible for gc are s1.a1.a2.a2 And s1.a1.a2.a2.a2
I know its a very long question but please can anyone tell me is it correct or not?