What do you call the concept where an object can have multiple types?
202520252025
What do you call the concept where an object can have multiple types?
- A.
Encapsulation
- B.
Polymorphism
- C.
Inheritance
- D.
Composition
Attempted by 4 students.
Show answer & explanation
Correct answer: B
Polymorphism is the object-oriented programming principle that lets a single reference, interface, or method call work with several different underlying types or implementations, so an object can be treated as more than one type depending on context.
Here, an object being usable as more than one type — for example, a subclass instance being passed around, stored, or returned wherever its superclass or an implemented interface is expected — is exactly this behaviour, so the concept being described is Polymorphism.
Encapsulation bundles an object's data and methods together and restricts direct access to its internal state — it controls visibility, not how many types the object can represent.
Inheritance sets up a parent-child relationship so a subclass reuses a superclass's members — it enables code reuse and hierarchy, but by itself does not describe an object behaving as more than one type.
Composition builds a class out of other objects as parts (a has-a relationship) — it describes how objects are assembled, not the ability to be treated as multiple types.