垃圾回收的三道SUN认证题,谁来给出答案并解释一下结果
12. Given the following,
1. class X2 {
2. public X2 x;
3. public static void main(String [] args) {
4. X2 x2 = new X2();
5. X2 x3 = new X2();
6. x2.x = x3;
7. x3.x = x2;
8. x2 = new X2();
9. x3 = x2;
10. doComplexStuff();
11. }
12. }
after line 9 runs, how many objects are eligible for garbage collection?
A. 0
B. 1
C. 2
D. 3
E. 4
14. Given the following,
12. X3 x2 = new X3();
13. X3 x3 = new X3();
14. X3 x5 = x3;
15. x3 = x2;
16. X3 x4 = x3;
48 Chapter 7: Objects and Collections
17. x2 = null;
18. // insert code
what two lines of code, inserted independently at line 18, will make an object eligible for
garbage collection? (Choose two.)
A. x3 = null;
B. x4 = null;
C. x5 = null;
D. x3 = x4;
E. x5 = x4;
15. Given the following,
12. void doStuff3() {
13. X x = new X();
14. X y = doStuff(x);
15. y = null;
16. x = null;
17. }
18. X doStuff(X mx) {
19. return doStuff2(mx);
20. }
at what point is the object created in line 13 eligible for garbage collection?
A. After line 15 runs
B. After line 16 runs
C. After line 17 runs
D. The object is not eligible.
E. It is not possible to know for sure.