public boolean equals(Point p){
...
}
The above method has nothing to do with equals(Object)
except sharing the name equals
. It does not override it, it cannot be invoked from an Object
-typed variable, there is no contract for it defined by Object
.
When you write
op.equals(p);
you are invoking a method on the Object
type. The only method called equals
in that type is equals(Object)
and this choice is permanent. The runtime can only provide a different override of equals(Object)
, but it will never route the call to equals(Point)
.
Similarly, when you write
p.equals(op);
the compiler will again see that you are invoking equals
with an argument whose static type is Object
, selecting equals(Object)
.