0
0
C++programming~5 mins

Access control in inheritance in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are the three main access specifiers in C++ inheritance?
The three main access specifiers are <strong>public</strong>, <strong>protected</strong>, and <strong>private</strong>. They control how base class members are accessible in derived classes.
Click to reveal answer
beginner
How does <code>public</code> inheritance affect access to base class members?
With <code>public</code> inheritance, <code>public</code> members of the base class remain <code>public</code> in the derived class, and <code>protected</code> members remain <code>protected</code>. <code>private</code> members are not accessible directly.
Click to reveal answer
intermediate
What happens to base class members when inherited with <code>protected</code> access?
When inherited as <code>protected</code>, both <code>public</code> and <code>protected</code> members of the base class become <code>protected</code> in the derived class. <code>private</code> members remain inaccessible.
Click to reveal answer
intermediate
Explain the effect of <code>private</code> inheritance on base class members.
With <code>private</code> inheritance, all <code>public</code> and <code>protected</code> members of the base class become <code>private</code> in the derived class. <code>private</code> members remain inaccessible.
Click to reveal answer
beginner
Can a derived class access the <code>private</code> members of its base class directly?
No, <code>private</code> members of the base class are not accessible directly by the derived class, regardless of the type of inheritance.
Click to reveal answer
In public inheritance, what access level do public base class members have in the derived class?
Apublic
Bprotected
Cprivate
Dinaccessible
Which inheritance type makes all inherited base class members private in the derived class?
Apublic
Bprotected
Cprivate
Dfriend
Can a derived class access the private members of its base class directly?
AYes, always
BNo, never
COnly with public inheritance
DOnly with protected inheritance
In protected inheritance, what happens to public members of the base class?
AThey become inaccessible
BThey remain public
CThey become private
DThey become protected
Which access specifier allows derived classes to access base class members but prevents outside access?
Aprotected
Bfriend
Cprivate
Dpublic
Describe how public, protected, and private inheritance affect the accessibility of base class members in a derived class.
Think about how each inheritance type changes the access level of base class members.
You got /4 concepts.
    Explain why private members of a base class are not accessible in derived classes, regardless of inheritance type.
    Consider the purpose of private access in object-oriented design.
    You got /3 concepts.