Let’s say I want to override the method equals() of Object:
public boolean equals(Object o){
//something
}
public boolean equals(SomeClass s){
//something else
}
SomeClass is obviously also an Object, so which method will be called if I use equals with an Instance of SomeClass as parameter?
That’s not overriding, it’s overloading. If you do that you’ll end up with two
equalsmethods: one that will be invoked for (subclasees of)SomeClassinstances and one for any other objects.One thing to note is that the method binding will be static: the compiler will decide which one to call based on the declared type of your reference. Therefore, the following will invoke the
equals(Object), notequals(SomeClass):