java of public, private, protected, default scope

Here Insert Picture Description
public: All categories visible
private: This class visible
protected: This package and all subclasses visible (a subclass of this package accessible subclass different packages can be accessed, is not a subclass can not access)
default (table package) : this package visibility (in this package and subclasses can access non-child classes, different packet classes and subclasses not accessible)

access modifiers in java, I feel that people share the secret level.
private individuals Secret
default (that is, do not write modifiers) community (neighbors) secret (in a package can access under the [package])
protected the family, community secret (and better than distant neighbors, in a non-static modification, not by new subclass parent object called directly)
public secret society (not secret)

protected:

  1. protected members of the base class is visible within the package and visible to a subclass;
  2. When the base class and subclass not in the same package, then the subclasses, subclasses instance can access its protected methods inherited from the base class, the base class can not access the protected methods instance.
Published 28 original articles · won praise 24 · views 10000 +

Guess you like

Origin blog.csdn.net/XM_no_homework/article/details/103847114