Q:

Java polymorphism and runtime method matching

For example I have following code.
class Circle {
    double radius;

    public boolean equals(Object circle) {
        return this.radius ==((Circle)circle).radius;
    }
}

And a Driver
public class Driver {
    public static void main(String[] args) {
        Object circle1 = new Circle();
        Circle circle2 = new Circle();
        System.out.println(circle1.equals(circle2));

    }
}

It prints True, but if I re-write Circle.equals() as
public boolean equals(Circle circle) {
    return this.radius ==((Circle)circle).radius;
}

where .equals() method takes Circle type, system would output False.
I know that Circle class is subclass of Object class, So compiler does not report error and at Runtime, JVM chooses correct override method to implement correct behavior. 
If I modify code as bottom one, where .equals() takes Circle Class objects, Code can implement correctly, please tell me why. Thanks in advance.

A:

With the method signature
public boolean equals(Circle circle) {

You are overloading equals, not overriding it; this is not a compiler error.  That means that Circle will inherit the Object implementation of equals, which simply compares object references to see if they are equal.  This returns false.
Your equals method should take an Object to override the method properly.  You should also use the @Override annotation, which will produce a compiler error if the annotated method doesn't override a method in the superclass.  The meethod body should test if its argument is an instance of the class before casting, so it can return false instead of throwing a ClassCastException.
Additionally, it's always a good idea to override hashCode if you are overriding equals.

