JAVA MODIFIERS/ACCESS SPECIFIERS
Access specifiers is a keyword that specifies how to access the member of a class there are four access specifiers.
![Java Modifiers: Access Control and Class Behavior" 1 modifiers](https://anuragedutech.com/wp-content/uploads/2024/02/modifiers-1024x768.png)
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.
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 |