Robotics C++ Physics II AP Physics B Electronics Java Astronomy Other Courses Summer Session  

Access Specifiers

 

 

 

Visibility Within

Members

 

private

default*

protected

public

Same class

Yes

Yes

Yes

Yes

Same package by subclass

No

Yes

Yes

Yes

Same package by non-subclass

No

Yes

Yes

Yes

Different package by subclass

No

No

Yes

Yes

Different package by non-subclass

No

No

No

Yes

 

 

  private: Provides the highest level of protection.

  default: Same as public unless the program is broken into packages.

      *Some texts refer to the case when no specifier is listed as "friendly". (Note that friendly is not used,however.)

  protected: Applies only when inheritance is involved.                                         

  public: Highest level of access.

     The code can be accessed by any other code in the program, including being  accessed by methods defined inside other classes.