Object-oriented programming (C++/OOP): Does creating a derived class require fundamental changes to the existing base class?\n\nChoose the most accurate statement about inheritance design and source-code impact.

Difficulty: Easy

Correct Answer: Incorrect

Explanation:


Introduction / Context:
Inheritance is a core concept in object-oriented programming (OOP). The question probes a common misconception: that introducing a derived (sub)class forces sweeping or “fundamental” changes to an existing base class. Sound OOP design emphasizes substitutability, encapsulation, and extensibility without retrofitting the base.



Given Data / Assumptions:

  • We have a stable base class that exposes a public/protected interface.
  • A new derived class will inherit from that base.
  • “Fundamental changes” means breaking public contracts, altering invariants, or reworking core behaviors of the base.


Concept / Approach:
Inheritance allows a derived class to reuse and extend behavior via the base’s public/protected interface. Because encapsulation hides implementation details, adding a subclass typically does not require modifying the base. If changes are needed, they are usually additive (e.g., adding virtual hooks or protected extension points) rather than fundamental. The Liskov Substitution Principle encourages designing bases so that derived types can slot in without base changes.



Step-by-Step Solution:

Identify base responsibilities and its stable interface.Confirm the derived class relies on existing public/protected members.Implement overrides/extra methods in the derived class; avoid touching private base data.Optionally add non-breaking extension points (virtual functions) if future variation is anticipated.Result: no fundamental base changes are required to introduce the derived class.


Verification / Alternative check:
Many frameworks (e.g., GUI toolkits) let you derive and override behavior without editing the base classes. If base redesign is routinely required, the abstraction is likely leaky and needs refactoring, not because inheritance intrinsically demands it.



Why Other Options Are Wrong:

  • Correct: Claims fundamental base changes are required; this contradicts encapsulation and standard OOP practice.
  • Not applicable / Depends on compiler / Only in multiple inheritance: Inheritance semantics are language-level; compilers do not demand such changes, and multiple inheritance is not a prerequisite.


Common Pitfalls:
Confusing “adding virtual” with “fundamental change”; conflating refactoring for better extensibility with a strict requirement; exposing base internals that force downstream edits.



Final Answer:
Incorrect

Discussion & Comments

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