Quiz Entry - updated: 2026.07.14
What are the three access specifiers in C++?
public (accessible anywhere), private (only inside the class), and protected (the class plus its derived classes).
* The three levels run from fully open (public) to fully closed (private), with protected sitting in between for subclasses. *
| Specifier | Accessible from |
|---|---|
public |
Anywhere |
private |
Only within the class |
protected |
Within the class and derived (sub)classes |
class Example {
public:
int a; // anyone can access
protected:
int b; // this class + subclasses
private:
int c; // this class only
};
Default access:
class→privateby defaultstruct→publicby default
Tip: Access control is about encapsulation — hiding internal state behind a controlled public interface so the rest of the program can't depend on (or corrupt) it.
Go deeper:
Access specifiers — cppreference — the exact rules for public/protected/private.
Access modifiers — Wikipedia — how the same idea appears across object-oriented languages.