Java difference in public, private, protected and default of

 

  Class data members and member functions having access to data comprising: public, private, protect, default (package access)

The scope of the current class in the same package other package descendant class 

public         √             √                   √              √ 

protected   √             √                    √              × 

friendly      √             √                    ×              × 

private      √             ×                    ×               × 

 

      This class visible priavte

      public all the classes visible

      This package protected and visible to all subclasses (subclasses of this package can access non-child classes, subclasses can access the different packages, can not access a subclass)

      This default package visibility (i.e. the default form) (a subclass of this package can access non-child category, a different package and subclasses of the class can not access)

Guess you like

Origin www.cnblogs.com/heqiyoujing/p/11222083.html