Difficulty: Easy
Correct Answer: Polymorphism
Explanation:
Introduction:
Many learners get confused between compile-time resolution (based on the static type of a reference) and runtime resolution (based on the dynamic type of the object). This question asks you to connect that behavior to the correct high-level object-oriented programming concept in C++.
Given Data / Assumptions:
Concept / Approach:
Polymorphism is the umbrella concept that covers both compile-time and runtime selection of behavior depending on types. In C++, overloading and templates are compile-time (the compiler checks the reference/parameter types), whereas overriding of virtual functions is runtime (the program checks the object’s dynamic type and uses late binding).
Step-by-Step Solution:
1) If a function call is not virtual (e.g., overloading), the compiler resolves it using the static type of the expression (the reference type).2) If the call is to a virtual function through a base reference/pointer, the runtime decides which override to invoke based on the dynamic object type.3) Both behaviors fall under polymorphism: ad-hoc (compile time) and subtype (runtime).4) Among the given options, the broad, correct concept name is “Polymorphism”.
Verification / Alternative check:
Create Base and Derived with a virtual function, call through Base& to a Derived object, and observe the Derived override executes. For an overloaded non-virtual function set, the compiler’s selection depends on the reference’s static type.
Why Other Options Are Wrong:
Inheritance: a relationship enabling reuse/subtyping, not the selection mechanism itself.Abstraction: exposing essential features while hiding details—unrelated to call dispatch.Encapsulation: bundling data/operations with access control—also unrelated to dispatch rules.
Common Pitfalls:
Assuming every member function call is dynamically bound. In C++, only virtual functions use runtime dispatch; others are resolved using the reference type at compile time.
Final Answer:
Polymorphism
Discussion & Comments