Java Access Modifiers

Access Modifiers in Java,which helps to control the accessing of any fields or methods or classes or interfaces but interfaces and abstract classes cannot be declared as a private or protected modifiers.

But any members of a class or interface can be declared using private or protected access specifiers.

Access Modifiers

public

If any of the class or method or field is declared using a public keyword, those classes or methods or fields can be accessible globally, means anyone access those class or method or fields.

default

Any of the class or method or any field declared without any access specifier will be considered as a default access specifier. Without any access modifier declaration of a class or method or fields can be visible or accessed with in the same package.

protected

If any of a method or field of a class is declared as with a protected keyword, those fields and methods can be accessible from the sub or child class of that class only. Other than child classes no other classes will be in a position to access those methods or fields.

private

If any of the method or field is declared with a private keyword, those method or fields cannot be accessible from outside of any class. Those fields or methods should be accessed within that class.