title: Role of new keyword in Java
body: <p>I am not sure how <code>new</code> keyword behaves in Java. Is it for sure that every time I will use <code>new</code> keyword, a new Object will be created on heap?</p>
  
  <p>I got this doubt when I was studying following example-</p>
  
  <pre><code>class Mixer {
    Mixer() { }
    Mixer(Mixer m) { m1 = m; }
    Mixer m1;
    public static void main(String[] args) {
      Mixer m2 = new Mixer();
      Mixer m3 = new Mixer(m2); // Does it create any new mixer object?
      m3.go();
      Mixer m4 = m3.m1;          m4.go(); 
      Mixer m5 = m2.m1;          m5.go();
    }
    void go() { System.out.print("hi "); }
  }
  </code></pre>
  
  <p>The line <code>Mixer m3 = new Mixer(m2);</code> invokes a constructor which does not create any new object. So, is it that no new object was created?</p>
  
  <p>Also, Which variable refers to which object in the end of program, i.e. till we get <code>NullPointerExcetion</code> for variable <code>m5</code>.</p>