title: Equal object in Java
body: <p>So this is from Head First Java (page 563)</p>
  
  <blockquote>
    <p>The default behaviour of hashCode() is to generate a unique integer
    for each object on the heap. <strong>So if you don’t override hashCode() in a</strong>
    <strong>class, no two objects of that type can EVER be considered equal.</strong></p>
  </blockquote>
  
  <p>But a simple Test will disprove this I think.</p>
  
  <pre><code>public class Song {
  
      private String name;
  
      public Song(String name) {
          this.name = name;
      }
  
      public String getName() {
          return name;
      }
  
  
      @Override
      public boolean equals(Object obj) {
          Song objectSong = (Song) obj;
          return this.getName().equals(objectSong.getName());
      }
  
  }
  </code></pre>
  
  <p>Well this will return true:</p>
  
  <pre><code>Song songA = new Song("A","B");
  Song songB = new Song("A","C");
  
  System.out.println(songA.equals(songB));
  </code></pre>
  
  <p>Am I missing something? What is it that the book is trying to tell me?</p>