Difficulty: Easy
Correct Answer: Public members of the base class become private members of derived class.
Explanation:
Introduction / Context:
Access conversion during inheritance is a subtle but important part of C++. With private inheritance, the intent is often to implement in terms of, rather than to expose an “is-a” relationship. Understanding how base-class access levels map into the derived class’s interface avoids surprises and preserves encapsulation.
Given Data / Assumptions:
Concept / Approach:
Under private inheritance, B’s public and protected members become private within D. That means clients of D cannot access B’s public API through a D object unless D explicitly re-exposes selected members (e.g., via using-declarations or forwarding functions). Private members of B remain inaccessible in D in all inheritance modes; they are part of B’s internal implementation.
Step-by-Step Solution:
Verification / Alternative check:
Create B with a public method and derive D privately. Attempt to call the method via D from non-friend code; it fails. Add using B::method; inside D to re-expose it; the call then succeeds, illustrating the mapping.
Why Other Options Are Wrong:
A: protected is not the result of private inheritance.
C: base private never becomes accessible.
D: public → public occurs only with public inheritance.
Common Pitfalls:
Final Answer:
Public members of the base class become private members of derived class.
Discussion & Comments