title: Class attribute variables - are references or a new object stored?
body: <p>Say I have a code:</p>
  <pre><code>public static void main(String[] args) {
      Animal r1 = new Animal(10,&quot;Amanda&quot;);
      House c = new House(100, r1);
      r1.setAge(3);
      
      House c2 = new House(101, r1);
      System.out.println(c);
      System.out.println(c2);
  }
  </code></pre>
  <p>The output is</p>
  <pre><code>3 Amanda
  
  3 Amanda
  </code></pre>
  <p>So it looks like what java does is store a reference to r1 in the Animal field value in House so that any changes to the object itself are reflected in any call to the Animal variable in the House class. Is that it? Or does java create a whole new object?</p>