Access Modifiers In Java

Access modifiers in Java are used to specify access levels for classes, variable methods and constructor.

Access Modifiers In Java default: The scope of default access modifier is limited to the package only. If we do not mention any access modifier, then it acts like a default access modifier.

Let’s see a practical example to understand this better.


private: The scope of private access modifier is only within the classes.

Note: Class or Interface cannot be declared as private


protected: The scope of protected access modifier is within a package and also outside the package through inheritance only.

Note: Class cannot be declared as protected


public: The scope of public access modifier is everywhere. It has no restrictions. Data members, methods and classes that declared public can be accessed from anywhere.


See this simple table to understand access modifiers easily

Access Modifiers In Java

Must Read: Java Tutorial

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

Leave a Comment

Share via
Copy link
Powered by Social Snap