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

Sharing is caring.

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn

Like This Post?

We have a lot more where that came from?

We only send really good stuff occasionally, promise.

Rajkumar SM

Leave a Comment

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

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on whatsapp

Recent Posts:

Scroll to Top
API Testing eBook

DOWNLOAD FOR FREE