Free Object-oriented basics lessonsObject-oriented basics · Stage 2 · Inheritance and polymorphism · Step 2
Overriding and overloading
Two ways the same method name appears twice, decided at different times, and the rules that tell them apart. About 13 minutes.
A class defines equals(Point p) intending to override Object's equals. Why might a HashSet<Point> ignore it?
- AIt overloads equals rather than overriding it, since the parameter type is Point, not Object
- BBecause equals is static
- CBecause Point has no hashCode
Show the answer
It overloads equals rather than overriding it, since the parameter type is Point, not Object. Collections call equals(Object); the overload is never used. @Override would have caught it.
4 questions on this idea
Short questions that apply the idea to new cases: trace it, work out a number, put steps in order. A wrong answer explains itself.
Answer them in your browserFree account, no card. Your progress is saved, and the idea comes back in a quick review later.
Sign up free to solve