title: Objects and Strings equality and memory digrams
body: <p>I have having a bit of trouble understanding the difference between these two: </p>
  
  <p>Suppose we have: </p>
  
  <pre><code> String x = "Test";
   String y = x;
   y = "Not Test"; //x is not modified here
  </code></pre>
  
  <p>The memory diagram for these two steps is the following: </p>
  
  <ol>
  <li>x-> "Test" </li>
  <li>x-> "Test" &lt;-y </li>
  <li>x-> "Test" y-> "Not Test"</li>
  </ol>
  
  <p>But, consider class A with field 'int var':</p>
  
  <pre><code>A a = new A();
  A b = a;
  b.var = 5; 
  </code></pre>
  
  <p>Here, if we modify b.var, a.var also changes to 5. Why is this different from the above case with strings? </p>
  
  <p>Additionally, I would appreciate it if someone wouldn't mind explaining these memory diagrams for strings and objects. Would the result be different if a and b were objects of different classes set equal? Thanks. </p>