title: Swapping variables in Java using a method
body: <p>I knew that in Java class instances are passed by references. I was trying to swap two class instances but it didn't worked. What I don't understand if they are passed through references then the code should have worked. What am I missing here?</p>
  
  <pre><code>public class Swapper {
  
      public static void main(String[] args) {
          NormalClass na = new NormalClass(1235);
          NormalClass nb = new NormalClass(5468);
          System.out.println("Before: 1st Object --&gt;");
          na.print_obj();
          System.out.println("Before: 2nd Object --&gt;");
          nb.print_obj();
  
  
          NormalClass.swap(na,nb);
  
  
          System.out.println("After: 1st Object --&gt;");
          na.print_obj();
          System.out.println("After: 2nd Object --&gt;");
          nb.print_obj();
  
      }
  
  }
  
  class NormalClass{
      public int _ID;
      public static void swap(NormalClass a, NormalClass b){
          NormalClass temp;
          temp = a;
          a = b;
          b = temp;
      }
      public void print_obj(){
          System.out.println(this._ID);
      }
      NormalClass(int __id){
          this._ID = __id;
      }
  }
  </code></pre>