title: How does gc method work?
body: <pre><code>public class GarbageC {
  public void finalize()
  {
  System.out.println("Finalize method");  
  }
  public static void main(String[] args) {
      GarbageC c1=new GarbageC();
      GarbageC c2=new GarbageC();
      c1=null;
      c2=null;
      System.gc();
      System.out.println("abc");
  }
  }
  </code></pre>
  
  <p>While I'm debugging this code, the o/p is coming as </p>
  
  <pre><code>Finalize method
  Finalize method
  abc
  </code></pre>
  
  <p>and when I run, I get this</p>
  
  <pre><code>abc
  Finalize method
  Finalize method
  </code></pre>
  
  <p>Why am I getting different outputs in both the cases</p>