title: == vs. equals() references/pointers JAVA
body: <p>I'm learning about == vs. equals() and doing various examples. For this one, I understand why r==s is false, but why is r.equals(s) false if they now both have the same content?</p>
  
  <pre><code>public class StringProgram{
    public static void main(String[] args) {
  
      Person r = new Person("A");
      Person s = new Person("J");
      s.setName("A");
  
      System.out.println(r.getName());//A
      System.out.println(s.getName());//A
      System.out.println(r==s);//false
      System.out.println(r.equals(s));//false
  
  
    }
  }
  </code></pre>
  
  <p>Here is the code of <code>Person</code> :</p>
  
  <pre><code>public class Person{
      private String name;
  
      public Person(String d){
      name=d;
      }
      public void setName(String a){
        name=a;
      }
  
      public String getName(){
        return name;
      }
  }
  </code></pre>
  
  <p>EDIT: I see that I have to override it now, but I still don't understand how the assignment works in the example below. I just don't understand why t.getName() is Keen if t is assigned to u.</p>
  
  <p>public class StringProgram{
    public static void main(String[] args) {</p>
  
  <pre><code>Person t = new Person("Gene");
  Person u = t;
  u.setName("Keen");
  
  System.out.println(t.getName());//Keen
  System.out.println(t.equals(u));//true
  </code></pre>
  
  <p>}
  }</p>