Access modifiers
There are four access rights in Java, and when different access rights are used, the modified content has different access rights, and the following table describes the ability to access different permissions:
Public protected Default Private
√√√√ in the same class
In the same package (subclass and unrelated classes) √√√
Sub-class √√ of different packages
Unrelated classes in different packages Yes
summarize: In the daily development process, write the class, method, member variable access
To be accessible only in this class , use the private modifier;
The classes in This package can be accessed without modifiers ;
To make the class in this package accessible to subclasses in other packages using the protected adornment
All The classes in the package can be accessed using the public adornment.
Note: If the class is decorated with public, the class name must be the same as the file name. There can be only one public-decorated class in a file.
Access modifiers, Java