Java OCA OCP Practice Question 149

Question

Given:

class Main { /*from  w  ww .  jav a 2 s  .  c o m*/
  Short story = 200; 
  Main go(Main cb) { 
    cb = null; 
    return cb; 
  } 
  public static void main(String[] args) { 
    Main c1 = new Main(); 
    Main c2 = new Main(); 
    Main c3 = c1.go(c2); 
    c1 = null; 
    // do Stuff 
} } 

When // do Stuff is reached, how many objects are eligible for garbage collection?

  • A. 0
  • B. 1
  • C. 2
  • D. Compilation fails
  • E. It is not possible to know
  • F. An exception is thrown at runtime


C is correct.

Note

Only one Main object (c1) is eligible, but it has an associated Short wrapper object that is also eligible.




PreviousNext

Related