Which of the following is not true in case of public inheritance in C++?
2018
Which of the following is not true in case of public inheritance in C++?
Answer: D. Each private member in the base class remains public in the derived class. — Concept: access rules under public inheritance When a class is derived using public inheritance, each base-class member that was public or protected keeps…
- A.
Each public member in the base class is public in the derived class.
- B.
Each protected member in the base class is protected in the derived class
- C.
Each private member in the base class remains private in the base class.
- D.
Each private member in the base class remains public in the derived class.
Attempted by 287 students.
Show answer & explanation
Correct answer: D
Concept: access rules under public inheritance
When a class is derived using public inheritance, each base-class member that was public or protected keeps that same access level when referenced through the derived class. A base class's private members are different: they cannot be referenced directly by the derived class's own code under any inheritance mode (public, protected, or private) — they remain usable only within the base class's own code (and its friends).
Application: checking each statement against the rule
A public member of the base class stays public in the derived class — this matches the rule, so it is true.
A protected member of the base class stays protected in the derived class (usable by the derived class's own code and the base class's own friends, not by ordinary outside code) — this matches the rule, so it is true.
A private member of the base class stays private to the base class itself — this is simply what 'private' means for the base class, independent of any inheritance; it is true.
A private member of the base class becoming public in the derived class — this contradicts the rule, because a base class's private members cannot be referenced directly by the derived class's own code under any inheritance mode, let alone as public members.
Cross-check: the two easily-confused private-member statements
"Remains private in the base class" describes the member staying inside its own base class — a fact about the base class alone, unrelated to inheritance, and always true.
"Remains public in the derived class" claims the member becomes directly accessible in the derived class's own code as a public member — this is what public (and every) inheritance mode denies, since a base class's private members cannot be referenced directly by the derived class's own code, let alone as public members.
So the statement claiming that a base class's private member remains public in the derived class is the one that is NOT true — that is the statement being asked for.