Please note that while
private
,
protected
and
public
are keywords, the
default access level is NOT a keyword. If we do not place either
private
,
protected
or
public
before a member variable or method, then it is automatically considered as
default access level.
- default (No Modifier) access level : If a variable or method is marked as default by not placing any access specifier, then that variable or method can be only accessed in that class, its same package sub-classes or in any other class belonging to the same package. But that variable or method can not be accessed in a sub-class or non-subclass belonging to a different package.
- protected access level : If a variable or method is marked as
protected
, then that variable or method can be only accessed in that class, its sub-classes (same-package or different package) or in any other class belonging to the same package. That variable or method is only not accessible in a non-subclass belonging to a different package.
- public access level : If a variable or method is marked as
public
, then that variable or method is accessible everywhere. There is no restriction on its access.
The following table summarizes the access control.
Please note that all the programs we have written till now had been using the default (No Modifier) access level.