C++ public inheritance: under public inheritance, how do base-class public members appear in the derived class?

Difficulty: Easy

Correct Answer: Public members of the base class become public members of derived class.

Explanation:


Introduction / Context:
Inheritance in C++ can be public, protected, or private. The chosen access specifier alters how base-class members are exposed through the derived class's interface. Public inheritance models an “is-a” relationship that preserves the base's public API, enabling substitutability (the Liskov Substitution Principle) and polymorphic use through base references or pointers.


Given Data / Assumptions:

  • We consider class D : public B.
  • Public/protected/private in the base determine initial accessibility.
  • Public inheritance preserves access of public and protected members (modulo rules stated below).


Concept / Approach:

Under public inheritance, the access levels are preserved for the derived interface: base public members remain public in the derived class; base protected members remain protected; base private members are not accessible directly by the derived class (though they exist as part of the object). This preservation is why clients can use a derived object wherever a base is expected. If you change the inheritance to protected or private, the visibility is reduced accordingly, but not under public inheritance.


Step-by-Step Solution:

Compare options to the rule of public inheritance. Only option D matches: base public → derived public. Options A/B contradict preservation; C discusses private members, which remain inaccessible, not promoted.


Verification / Alternative check:

Write a base with a public method and derive publicly; call that method on a derived instance from client code. It compiles, showing the public interface was preserved.


Why Other Options Are Wrong:

A/B — would reduce visibility, not how public inheritance behaves.

C — private members are not inherited as accessible members; they remain hidden.


Common Pitfalls:

  • Assuming private members “become” protected or public—they do not.
  • Forgetting that overriding access can also be applied per-member in the derived class.


Final Answer:

Public members of the base class become public members of derived class.

More Questions from Objects and Classes

Discussion & Comments

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