Guys I know this question is silly but just to make sure:
Having in my class method:
boolean equals(Document d)
{
//do something
}
I’m overloading this method nor overriding right? I know that this or similiar question will be on upcoming egzam and would be stupid to not get points for such a simple mistake;
You are not even overloading, since the other method is called
equals. But if you add thats, you will be overloadingequals. Although, to be precise, we talk about overloading if two (or more) methods with the same name but different signature are defined in the same class. In your case, it is trickier, since yourequalswith its different signature partly hides the originalequals. Which is usually a bad thing, because this almost always leads to hard to understand behaviour, thus subtle bugs. Whenever someone callsequalson an instance of your class, depending on the parameter type the call may go to a different implementation of the method.You would be overriding
Object.equalsif you defined your method with the exact same signature as the original, i.e.In this case, both of the above calls to
equalscorrectly executeDocument.equals.