The 3 keywords can be applied to:
- classes and
- data members and member functions.
We first look at applying them to data members or functions.
When you declare the members as public, the public keyword specifies that those members are accessible from any function, including functions in the derived class.
Take note that the default access of members in a class is private. So if the 3 keywords are omitted, the members will be treated by the compiler to be of private members.
When private keyword is applied to members, it specifies that those members are accessible only from member functions of the same class. They can’t be accessed by the derived members of the class.
When you declared members as protected, only member functions of the same class and its derived class could access them.