What is the default inheritance access specifier when a C++ class is derived from a struct?
Options
- A. Private
- B. Protected
- C. Public
- D. More than one of the above
- E. None of the above
Quiz Practice:
A. Private
Answer: (A) Private
When inheritance is declared using the class keyword, the default inheritance mode is private, even if the base type is a structure.
For example:
struct Base { };
class Derived : Base { };
Here, the inheritance is private by default because Derived is declared using class.
The keyword used for the derived type determines the default inheritance access: a class defaults to private inheritance, while a struct defaults to public inheritance.