Inherited member availability: If the base class defines a member function func(), and the derived class does not define a function with that name, can an object of the derived class call func()? Provide the correct evaluation.
-
AIncorrect statement — the derived object can call func() if it is accessible via inheritance.
-
BCorrect statement — the derived object cannot call func() unless it redefines it.
-
CCorrect only if func() is virtual.
-
DCorrect only with protected inheritance.
-
ECorrect only if using explicit qualification with the base scope.
Answer
Correct Answer: Incorrect statement — the derived object can call func() if it is accessible via inheritance.
Explanation
Introduction / Context: The claim suggests a derived object cannot access a base member unless the derived redeclares it. In C++, members of the base are part of the derived object as long as they are not hidden and remain accessible under the chosen inheritance mode (public/protected/private) and access level (public/protected).
Given Data / Assumptions:
- Base declares a function
func()that is accessible to Derived (e.g., public). - Derived does not declare another
func(). - Use public inheritance for typical behavior.
Concept / Approach: With public inheritance, public base members remain public in the derived interface. Therefore, calls like Derived d; d.func(); are perfectly valid. Virtual is not required to call the function; virtual only affects which implementation runs when calling through a base interface and enabling overriding. If Derived declared another overload with the same name, name hiding could affect lookup, but in the scenario stated, no such overload exists.
Step-by-Step Solution:
Base::func() exists and is accessible. Derived does not declare its own func(). An expression of type Derived calls func() → Base::func() executes.Verification / Alternative check: Change inheritance to private: public members of Base become private within Derived and may not be callable from outside via a Derived object, but still callable inside Derived’s own member functions — showing access control matters, not the existence of an override.
Why Other Options Are Wrong:
- “Cannot call unless redefined”: incorrect; inheritance exposes the base implementation.
- “Only if virtual”: virtuality is not required for direct calls.
- “Requires base scope qualification”: not necessary unless hidden by another declaration.
Common Pitfalls: Confusing overriding with availability; and conflating access specifiers with the need to redeclare symbols in the derived class.
Final Answer: Incorrect statement — the derived object can call func() if it is accessible via inheritance.