ITPEC FE Morning October 2019 Question 47
In object orientation, which of the following is the name of being able to use the attributes and functions of a class in a subclass of that class?
Explanation
Inheritance — a subclass takes over the attributes and methods defined in its superclass and can use them as its own.
In object orientation, a subclass is defined as a specialisation of an existing class. Through inheritance it gets the superclass's attributes and methods without redefining them, and adds or changes only what differs. For example, a SavingsAccount subclass of Account inherits balance and deposit( and adds an interest rate. Common features are written once, in the superclass, and reused.
Answer (b)
Why not others:
- •(a) Encapsulation — bundling data with the methods that operate on it and hiding the internals behind an interface
- •(c) Override — a subclass redefines an inherited method with the same name and signature; it replaces the superclass's behaviour rather than simply using it
- •(d) Polymorphism — the same message produces different behaviour depending on the class of the object that receives it
Key rule: Inheritance reuses superclass features, overriding changes an inherited method, polymorphism lets one call behave differently per class, and encapsulation hides the inside.
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.