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

Get our latest blog posts delivered to your inbox

Subscribe and get popular blog posts about software testing industry.


Leave a Comment

Share via
Copy link
Powered by Social Snap