Foreword
Java object-oriented three properties: encapsulation, inheritance, polymorphism. This article will introduce the principle of
Package
Packaging is to achieve the kind of access control. Hide implementation details so that like users can only be accessed through pre-customized method for data, control logic can be conveniently added, unreasonable limit operational attributes
easy to modify, enhance the maintainability of the code.
Modifiers | similar | A package of the same class | Subclass outer package | Like other packages |
---|---|---|---|---|
private | √ | |||
default | √ | √ | ||
protected | √ | √ | √ | |
public | √ | √ | √ | √ |
- private: the same class can access this member.
- default: the same package of class members can access this memory.
- protected: the same package classes and subclasses of the outer package members can access this memory.
- public: any class can access this member.