OO concept check: what do we call it when the same operation (method name) can be applied to different classes with behavior appropriate to each class?
-
AInheritance
-
BPolymorphism
-
CEncapsulation
-
DMultiple classification
Answer
Correct Answer: Polymorphism
Explanation
Introduction / Context:Object-oriented programming promotes code reuse and flexibility through encapsulation, inheritance, and polymorphism. When a common operation name is implemented differently across classes yet invoked uniformly, we are using polymorphism.
Given Data / Assumptions:
- A shared method name exists across multiple classes (for example, draw() on Shape subtypes).
- Each class provides its own implementation.
- Calls are resolved appropriately at compile time (overloading) or run time (overriding), depending on language and context.
Concept / Approach:Polymorphism literally means “many forms.” Through interface or superclass references, the same operation name results in class-specific behavior. This is foundational for extensible designs and polymorphic collections.
Step-by-Step Solution:
Compare definitions: inheritance (is-a relationship), encapsulation (information hiding), polymorphism (many forms).Map the described behavior to polymorphism.Confirm: the same message produces different effects depending on the receiver’s class.Verification / Alternative check:Example: List.toString() behaves differently for ArrayList and LinkedList but can be invoked via a List reference.
Why Other Options Are Wrong:Inheritance defines type hierarchy, not behavior resolution itself. Encapsulation hides internal state/implementation. Multiple classification is not a standard OO pillar in this context.
Common Pitfalls:Confusing overloading (same method name, different parameter lists) with overriding (same signature, different classes). Both are forms of polymorphism but operate at different binding times.
Final Answer:Polymorphism