| Scope |
Current class |
Same package |
Descendant class |
Other Package |
| Public |
√ |
√ |
√ |
√ |
| Protected |
√ |
√ |
√ |
X |
| Friendly (default) |
√ |
√ |
X |
X |
| Private |
√ |
X |
X |
X |
Friendly is the default access permission (the member variable is not public protected and private)
Focus on the difference between protected and fiendly two kinds of permissions: For protected member variables, descendant classes can be accessed anywhere (inside or outside the package), but for friendly or default member variables, there is no descendant class access concept, This means that if the descendant class is within the package, it can be accessed, and the descendant class is not accessible outside the package. Protected can be accessed in its subclasses, regardless of whether they are in a subclass or an instance of a subclass, regardless of which package they are in, but if the subclass is not in the same package as the parent class, and the child class is accessed with an instance of the parent class
The difference between Java protected and default permissions