Before explaining the Four keywords, I want Class Make a simple definition of the relationship between them. Class , Base Class It can be thought that they are all their children, and Classes And think they are all friends of their own.
1,Public:PublicIndicates that the data member and member function are open to all users, and all users can directly call the function.
2,Private:PrivatePrivate means thatClassNo one except yourself can use it directly. Private property cannot be infringed. Even children and friends cannot use it.
3 , Protected : Protected For children and friends Public Can be used freely, without any restrictions, and for other external Class , Protected It becomes Private .
Scope: current class, same package, Child class, other package
Public √
Protected √ ×
Friendly √ ××
Private √ ×××
The default value is friendly when no data is written.