0
0
C++programming~5 mins

Access specifiers in C++ - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What are the three main access specifiers in C++?
The three main access specifiers in C++ are <strong>public</strong>, <strong>private</strong>, and <strong>protected</strong>. They control the visibility of class members.
Click to reveal answer
beginner
What does the private access specifier do?
Members declared private can only be accessed within the same class. They are hidden from outside code and derived classes.
Click to reveal answer
intermediate
How does protected differ from private?
<code>protected</code> members are like <code>private</code> but can also be accessed by derived (child) classes, not just the class itself.
Click to reveal answer
beginner
What is the default access specifier for class members in C++?
By default, members of a class are private if no access specifier is given.
Click to reveal answer
beginner
What is the default access specifier for struct members in C++?
By default, members of a struct are public if no access specifier is given.
Click to reveal answer
Which access specifier allows members to be accessed from anywhere?
Apublic
Bprivate
Cprotected
Dinternal
If no access specifier is given in a class, what is the default?
Apublic
Bprivate
Cprotected
Dfriend
Which access specifier allows derived classes to access members but hides them from outside?
Apublic
Bstatic
Cprivate
Dprotected
What is the default access specifier for members of a struct?
Apublic
Bprotected
Cprivate
Dnone
Can private members be accessed directly by derived classes?
AOnly if friend class
BYes
CNo
DOnly if public inheritance
Explain the difference between public, private, and protected access specifiers in C++.
Think about who can see or use the class members.
You got /3 concepts.
    What are the default access levels for class and struct members in C++?
    Remember the difference between class and struct.
    You got /2 concepts.