AccessSpecifiers
AccessSpecifiers
(Visibility Modes)
Access Specifiers
One of the techniques in object-oriented
programming is encapsulation.
It concerns the hiding of data in a class
and making this class available only
through methods. In this way the
chance of making accidental mistakes
in changing values is minimized.
Access Specifier defines the
boundary and scope to access the
method, variable and class
Access Specifiers
Java offers four access specifiers,
listed below in decreasing
accessibility:
public
protected
default (no specifier)
private
Access Specifier -
public
public classes, methods, and fields can be
accessed from everywhere.
public Y Y Y Y
protected
(subclass in other Y Y Y N
package)
No
specifier/default/frie
Y Y N N
ndly/
package private
private Y N N N