title: Pointers and objects in java
body: <p>let's consider the following code:</p>
  
  <pre><code>public class Test {
  
      private int a;
  
      public Test(){
          this.a = 1;
      }
  
      public static void main(String[] args) {
          Test A = new Test();
          Test B = A; 
  
          // TEST1
          B.a = 0;
          System.out.println(A); // prints 0
  
          // TEST2
          B = null;
          System.out.println(A); //  also prints 0
      }
  
      public String toString(){
          return Integer.toString(this.a);
      }
  
  }
  </code></pre>
  
  <p>In TEST1, we modify <code>B</code> and then <code>A</code> is modified because <code>B</code> points to <code>A</code>.
  I may understand why in TEST2 <code>A</code> doesn't become <code>null</code>, because <code>B</code> now points to <code>null</code>.</p>
  
  <p>But the results of the two tests seem contradictory: why <code>A</code> doesn't become null ?</p>
  
  <p>Thanks.</p>