1 Reply Latest reply: Nov 4, 2012 10:48 AM by rp0428 RSS

    At which line , Object is Garbage collected.

    user12203354
      1. public class GC { 
      2.  private Object o; 
      3.   private void doSomethingElse(Object obj) { o = obj; }
      4.   public void doSomething() { 
      5.  Object o = new Object(); 
      6.  doSomethingElse(o); 
      7.   o = new Object(); 
      8.   doSomethingElse(null);
      9  o = null; 10. } 
       } 
      When the doSomething method is called, after which line does the Object created in line 5 become available for garbage collection?
      A. Line 5
      B. Line 6
      C. Line 7
      D. Line 8
      E. Line 9
      F. Line 10

      I think it should be line 9.but answer is 8....
      How is it line 8?

      Edited by: user12203354 on Nov 4, 2012 9:38 PM