Practice mode C++

When a struct is derived from a base class without an access specifier, as in struct D : B {}, what kind of inheritance is used?

Correct answer C. public

Explanation

The only difference between class and struct in C++ is the default access: struct defaults to public for both members and base classes, while class defaults to private. So struct D : B means public inheritance, whereas class D : B would mean private inheritance. Virtual inheritance is never a default; it always needs the virtual keyword.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.