title: Java Object Assignment
body: <p>I am new to Java and I have some questions in mind regarding object assignment. For instance,</p>
  
  <pre><code>Test t1 = new Test();
  Test t2 = t1;
  t1.i=1;
  </code></pre>
  
  <p>Assuming variable <code>i</code> is defined inside Test class, am I right to assume both t1 and t2 point to the same object where the modification <code>t1.i=1</code> affects both <code>t1</code> and <code>t2</code>? Actually I tested it out and seems like I was right. However when I try the same thing on <code>String</code>, the modification happens only on one side where the other side is unaffected. What is the reason behind this?</p>
  
  <p>Edit: The case I tried with String.</p>
  
  <pre><code>String s1 = "0";
  String s2 = s1;          
  s1 = "1";
  System.out.println(s1);
  System.out.println(s2);
  </code></pre>
  
  <p>I realise my mistake by testing the cases on String since it is immutable. The situation where I thought <code>s1="1"</code> modify the string is in fact returning the reference of "1" to the s1. Nevertheless, my question remains. Does <code>Test t2 = t1;</code> cause both t2 and t1 point to the same object or each now have their own objects? Does this situation applies on all objects on Java?</p>