What are the types of access specifiers in Java?

In Java, access specifiers are the keywords which are used to define the access scope of the method, class, or a variable.

There are four access specifiers in java.

Public - The classes, methods, or variables which are defined as public, can be accessed by any class or method.

Protected - Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.

Default - Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.

Private - The private class, methods, or variables defined as private can be accessed within the class only.

In Java, access specifiers are the keywords which are used to define the access scope of the method, class, or a variable.

There are four access specifiers in java.

Public – The classes, methods, or variables which are defined as public, can be accessed by any class or method.

Protected – Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.

Default – Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.

Private – The private class, methods, or variables defined as private can be accessed within the class only.

Sriram Mannava
Sriram Mannava

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity.

Leave a Reply

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