title: Adding objects to hashmap as keys which only equals method implemented
body: <p>I have the below class which only equals is overridden,</p>
  
  <pre><code>class S {
  
      String txt = null;
  
      S(String i) {
          txt = i;
      }       
  
      public boolean equals(Object o) {
          S cc = (S) o;
          if (this.txt.equals(cc.txt)) {
              return true;
          } else {
              return false;
          }
      }
  
      //Default hash code will be called
      /*public int hashCode(){
          return txt.hashCode();
      }*/
  
  }
  </code></pre>
  
  <p>I add this class objects to a hash map as below,</p>
  
  <pre><code>    public static void main(String args[]) {
              S s1 = new S("a");
              S s2 = new S("b");
              S s3 = new S("a");
  
              Map m = new HashMap();
              m.put(s1, "v11");
              m.put(s2, "v22");
              m.put(s3, "v33");
  
              System.out.println(m.size());
              System.out.println(m.get(s1));
      }
  </code></pre>
  
  <p>Can explain the result 3 and v11 is printed? Shouldnt the value v11 of s1 is replace by v33 because same equals key is put as s3?</p>