Before explaining the Four keywords, I want to make a simple definition of the relationship between classes. For a class that inherits its own, the base class can think that they are all their children, classes in the same directory as yourself are considered to be your friends.
1. Public: indicates that the data member and member function are open to all users and can be directly called by all users.
2. Private: Private indicates private. Private means that no one except the class itself can directly use private property. Private property cannot be infringed, even if it is a child or friend, none.
3. Protected: for children and friends, protected is public and can be used freely without any restrictions. For other external classes, protected becomes private.
Scope: current class, same package, Child class, other package
Public √
Protected √ ×
Friendly √ ××
Private √ ×××
Note: friendly is used by default when no data is written.