Which OOP concept means deciding at runtime which method implementation to invoke for a call through a base interface? Identify the correct term used in C++ for this behavior.

Difficulty: Easy

Correct Answer: Dynamic binding

Explanation:


Introduction:
Object-oriented languages dispatch virtual calls using the most-derived override that applies at runtime. This question asks for the term that describes runtime decision-making for which method body to execute in C++.


Given Data / Assumptions:

  • Virtual functions are involved.
  • Call is made through a base-class interface or pointer/reference.
  • Language: C++.


Concept / Approach:
The correct term is dynamic binding (also called late binding). With dynamic binding, the program chooses the function implementation based on the runtime dynamic type of the object, not merely the static type of the expression.


Step-by-Step Solution:
1) Declare a virtual function in the base class.2) Override it in derived classes.3) Call through a base pointer/reference; the runtime type determines which override runs.4) The dispatch commonly uses a vtable/vptr mechanism on typical implementations.


Verification / Alternative check:
Construct a small example with Base::foo virtual and Derived::foo override; observe that calling foo via Base* to a Derived object executes Derived::foo.


Why Other Options Are Wrong:
Data hiding: refers to encapsulating implementation details, not dispatch.Dynamic Typing: C++ is statically typed; RTTI is not dynamic typing.Dynamic loading: means loading code/modules at runtime, unrelated to method dispatch choice.


Common Pitfalls:
Confusing dynamic binding with templates (which are resolved at compile time) or assuming all member functions are dynamically bound without the virtual keyword.


Final Answer:
Dynamic binding

More Questions from OOPS Concepts

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion