title: Casting down the hierarchy and equals in java
body: <p>I have the following code </p>
  
  <pre><code>@Override
  public boolean equals(Object o) {
      if (!(o instanceof ColorPoint))
          return false;
      return super.equals(o) &amp;&amp; ((ColorPoint) o).color == color;
  }
  </code></pre>
  
  <p>And i have the following</p>
  
  <pre><code>Point p = new Point(1, 2);
  ColorPoint cp = new ColorPoint(1, 2, Color.RED);
  </code></pre>
  
  <p><code>ColorPoint</code> inherits <code>Point</code>. The problem is when I do <code>p.equals(cp)</code> why it return <code>true</code>? I mean in the last return it call <code>super.equal</code> but at that cast what happens? What it returns at that cast with <code>ColorPoint</code></p>
  
  <pre><code>@Override public boolean equals(Object o) {
  if (!(o instanceof Point))
  return false;
  Point p = (Point)o;
  return p.x == x &amp;&amp; p.y == y;
  }
  </code></pre>
  
  <p>This is the equal from Point class</p>