ITPEC FE Morning April 2020 Question 8
In object-oriented programming, which of the following is an explanation of overriding that achieves polymorphism?
Explanation
A subclass providing its own implementation of a superclass method — that is overriding, and it is what makes polymorphism work.
The subclass redefines an inherited method with the same name and signature. When the method is called, the version in the object's actual class runs, so code written against the superclass gets each subclass's own behaviour.
Answer (a)
Why not others:
- •(b) — collecting the common properties of several classes into one class is generalization, which creates the superclass rather than redefining its methods
- •(c) — same name with a different number, type or order of arguments is overloading, chosen at compile time from the argument list
- •(d) — hiding an object's internal structure behind its external specification is encapsulation (information hiding)
Key rule: Same name and same signature in a subclass is overriding, chosen at run time; same name with different parameters is overloading, chosen at compile time.
System Development Technology · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.