Public Protected Private Modifiers in Java

Image for post
Image for post

Many Java developers are trying to understand the difference between access modifiers such as private, public, protected and no-modifier.

Image for post
Image for post
src: stackoverflow.com/a/215505/5385988

Table above shows everything needed however, I believe it is easier to remember the explanations below.

Private modifier, hides access from other classes within the package.

Public modifier, exposes access to every other classes independent of package level.

Protected modifier, works like public modifier, it only limits access to world (eg. out of project access)

No-modifier, restricts access from different packages.

You may want to check the official documentation here for more information.

Follow me on Medium and Twitter for latest posts.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store