Difficulty: Easy
Correct Answer: friend
Explanation:
Introduction / Context:
When declaring inheritance in C++ (class Derived : access Base {}), you choose an access specifier that controls how the base’s public and protected members are treated in the derived class’s interface. Knowing which keywords are legal in the base-specifier list is fundamental C++ syntax knowledge.
Given Data / Assumptions:
Concept / Approach:
Valid access specifiers in an inheritance list are exactly public, protected, and private. They adjust the accessibility of inherited members in the derived class. The keyword friend grants access privileges to another function or class and is not an access specifier for inheritance. Therefore it cannot appear as a visibility label in the base-specifier list.
Step-by-Step Solution:
Verification / Alternative check:
Try compiling class D : friend B {}; — compilers emit a syntax error. Replacing friend with public or protected compiles successfully (assuming B is declared).
Why Other Options Are Wrong:
public/private/protected are explicitly supported by the language for inheritance.
Common Pitfalls:
Final Answer:
friend
Discussion & Comments