ITPEC FE Morning October 2019 Question 9

In object-oriented programming, which of the following is an explanation of overriding that achieves polymorphism?

Explanation

A subclass provides its own implementation of a method its superclass already has — that is overriding, and it is what makes polymorphism work.

The overriding method keeps the same name and signature but replaces the body. When code calls the method through a superclass reference, the version in the object's actual class runs, chosen at run time. One call therefore behaves differently for different kinds of object.

Answer (a)

Why not others:

  • •(b) — generalization: collecting the common properties of several classes into a superclass; it builds the hierarchy that overriding then works on
  • •(c) — overloading: methods with the same name but a different number, type or order of arguments, chosen at compile time from the arguments
  • •(d) — encapsulation (information hiding): keeping an object's internal structure out of its external specification

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.