header-logo.png GKINDEX

Java Access Specifiers

Java Access specifiers helps to regulate the accessing of the other classes, fields and methods.

Java has the following four access specifiers.

  • public

  • private

  • protected

  • default

public

If any class or method or field is declared as a public, those classes or methods or fields can be accessible from outside of any class or method. You can say it grants a universal access.

private

If any class or method is declared as a private, those class or method or fields cannot be accessible from outside of any class or method. Those classes or methods can be accessible from within the same class.

protected

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

default

This is a default access specifier, if we don't specify any access specifier then JVM assume as a default specifier. default classes or methods or fields can be accessed with in the same package.

  • Share