DEV Community

devcse
devcse

Posted on

What is the difference between public, protected and private in Java?

Public, Private and Protected are called access modifier in java. This are the reserved keyword in java. They are defined the access of the classes and interfaces. And when one of them are not defined then it’s called default access modifier.

Basically public exposes to classes outside the package, private hides from other classes within the package and protected is a version of public restricted only to the subclasses. Ok, Let’s see an overview how the keywords defined the access of the classes and the interfaces.

Learn more: https://codesnipeet.com/what-is-the-difference-between-public-protected-and-private-in-java/

Top comments (0)