Several access rights modifiers
public,protected,private,friendly (there is no such modifier in Java, that is, the package access permission, no access modifiers are provided)
When used, it is placed before the definition of a member (domain or method) in a class, and only controls the access rights of the specific definition it modifies.
Package access rights
is the default access permission, without any keywords
All other classes in the same package have access to this member, and for all other classes outside the package, there is no access permission.
The way to access access to a member is as follows:
- Decorate members with public, anyone with access rights anywhere
- Do not add access modifiers and place other classes inside the same package
- Inherited, inherited classes can access the public and protected members of the parent class
- Provides get and set methods to read and change values (the basic principle of JavaBeans)
Public: Interface access rights
It's accessible to everyone.
Private: Unable to access
In addition to the class that contains the member, no other class can access the member
Protected: Inheriting access rights
The protected members of a base class can be accessed only by derived classes (other classes within the same package are also accessible)
Java Programming thought Learning (iv) Access rights