Reprint: http://wuhaidong.iteye.com/blog/851754
There are 4 types of access modifiers in the Java language
There are 4 access modifiers in the Java language: package (default), private, public, and protected.
1. The package is the default protected mode, plus a packet access, which is used when there are no modifiers. Package access allows domains and methods to be accessed by any method of any class within the same package. (In-package access).
2. Private identifies access patterns that represent private domains and methods that can only be accessed by other methods in the same class, implement data hiding, and, if necessary, access private variables through methods. (In-class access).
3. The public modifier is used to expose domains and methods so that they can be accessed outside of the package defined by the class. This level is also required for the necessary interface elements in the package and class, and the main () method must be public, and the ToString () method must also be public. It is not common to expose a domain with public unless the domain has been declared final. (Cross-package access).
4. The protected modifier provides a way to access the package (with restrictions) from outside the package. Adding protected modifiers before fields and methods does not affect access to them by methods of other classes within the same package. To access the package from outside the package, which contains the protected member's class, you must ensure that the class being accessed is a subclass with the protected member class. That is, you can use this level when you want a class in the package to be reused by classes outside of the package. Should be used with caution in general. (The class in the package is used with caution in the outer class inheritance).
There are 4 types of access modifiers in the Java language