Java Modifiers: Access Control and Class Behavior”

JAVA MODIFIERS/ACCESS SPECIFIERS

Access specifiers is a keyword that specifies how to access the member of a class there are four access specifiers.

modifiers

Private: – private members of a class are not accessible in a class in the same package or in another class in another package private gives more security.

Public: – public members of a class are available in a class in the same package or in the some other class in another package universal scope.

Protected: –  protected  members of a class are available to another classes in some package but not in another package. Protected members are available in the sub class in any package.

Default: – default member are available to the classes in the same package but not in another package.

Java Access Modifiers Table
S. No Access Modifier Within class Within package Outside package by subclass Outside package
1 public Yes Yes Yes Yes
2 protected Yes Yes Yes No
3 default (no modifier) Yes Yes No No
4 private Yes No No No

Leave a Comment

Your email address will not be published. Required fields are marked *