There are four access modifiers in Java: public,protected,default,private
Note: This is about access to the properties and methods in the class, not the access rights of the class
1.default: Package access rights
If nothing is written, default defaults. Of course, you can also explicitly give the default permission
The properties and methods of the default adornment, all other classes in the package have access to that member, but no access to all classes outside of the package.
2.public: Interface access rights
Public-decorated properties and methods are visible to each class
3.private: In-Class access rights
Private and public, private-decorated properties and methods are not accessible to other classes except the class itself.
4.protected: Inherit access rights
First, protected provides the package access rights. In other words, if two classes are within the same package, default and protected provide the same access to the class where the caller resides.
If not in a package, protected provides inherited access, which means that subclasses can access properties and methods that are protected decorated in the parent class.
Their relationship is as follows:
|
In-Class |
Inherited |
In-Package |
All other |
Public |
Is |
Is |
Is |
Is |
Protected |
Is |
Is |
Is |
Whether |
Default |
Is |
Is |
Whether |
Whether |
Private |
Is |
Whether |
Whether |
Whether |
Permission access modifiers in JAVA (public,protected,default,private)