Which method will be called when overriding a method with different parameters in the following case?

equals, java, object

Solution

That's not overriding, it's overloading. If you do that you'll end up with two `equals` methods: one that will be invoked for (subclasees of) `SomeClass` instances 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)`, not `equals(SomeClass)`:

Object o = new SomeClass();
o.equals(o);  // invokes SomeClass.equals(Object)

Problem

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?

Original source

Related problems