Difficulty: Easy
Correct Answer: Incorrect — access does not work upward; base members do not gain access to derived members.
Explanation:
Introduction / Context:
The statement probes a common misunderstanding: that accessibility is symmetric across inheritance. In reality, inheritance grants the derived class visibility into the base’s accessible members, not vice versa. Base classes do not magically see derived members simply because a derived type exists.
Given Data / Assumptions:
Concept / Approach:
Access control is independent of object identity. A base-class member function is compiled in the context of Base, so it can access members declared in Base (per access specifiers) but not those declared later in Derived. While you can pass a Derived instance to a base function, that does not change what members the code is permitted to access. Virtual dispatch lets a derived override change behavior when called via a base interface, but it does not alter access rights of base code to derived data.
Step-by-Step Solution:
Verification / Alternative check:
Try to compile Base::f() referencing a Derived-only field; the compiler errors because the name is unknown in Base’s scope. Overriding a virtual in Derived does not grant Base visibility into Derived members.
Why Other Options Are Wrong:
Common Pitfalls:
Equating polymorphism (which member executes) with access rights (what names are visible within code).
Final Answer:
Incorrect — access does not work upward; base members do not gain access to derived members.
Discussion & Comments