Java中修饰符分类
Java中包含四种访问权限修饰符,分别为
- private
- default
- protected
- public
修饰符访问权限
- private:visible to the class only,只能在类内部访问,或通过get、set方法访问;
- default:visible to the package,只能在同一个包层级下访问,包下的子包及子包内的子类,都不能访问default修饰的变量或方法;
- protected:visible to the package and all the subclasses,对同一层级包,及对其所有子类可见,其子包下的非子类不可见;
- public:visible to the world;