Java OCA OCP Practice Question 2955

Question

Given:

2. public class Main {  
3.   static Main st;  
4.   public static void main(String[] args) {  
5.     new Main().go();  
6.     // what's eligible?  
7.   }  //from w ww .jav  a  2s.co  m
8.   void go() {  
9.     MyInner in = new MyInner();  
10.     Integer i3 = in.doInner();  
11.     Main t = new Main();  
12.     st = t;   
13.     System.out.println(i3);  
14.   }   
15.   class MyInner {  
16.     public Integer doInner() { return new Integer(34); }  
17.   }  
18. } 

When the code reaches line 6, which are eligible for garbage collection? (Choose all that apply.)

  • A. st
  • B. in
  • C. i3
  • D. The object created on line 5.
  • E. The object created on line 9.
  • F. The object created on line 10.
  • G. The object created on line 11.


D, E, and F are correct.

Note

A, B, and C are incorrect because only objects are considered by the GC.

G is incorrect because main() could still access line 11's Main object through st.




PreviousNext

Related