Public, Private, Protected, and default identifiers

Private methods/properties (priviate int a;) can’t be accessed from outside of the class.
Protected (protected int a;)can be accessed in the class or from its sub-class.
Public (public int a;)can be accessed from any places.
The methods/properties without any identifier (int a) can be access by the classes within the same package; but can’t be accessed out of the package.

In a class, all identifiers can access each other. So in fact “identifier” is for “external” access.

原文地址:https://www.cnblogs.com/backpacker/p/2271188.html