Java Access Modifiers

Quang Nguyen
Sep 3, 2018 · 1 min read

Here a list of access modifiers in Java and what they entails if you decide to use them.


Restrictive spectrum

Least ← — — — →Most

Private, Default, Protected, Public

Private:

  • only accessible inside a class

Default (no access modifier specified):

  • accessible inside class, same package class and subclass

Protected:

  • same as default with the addition of accessibility inside other package subclasses

Public:

  • accessible everywhere

The following are access modifiers that doesn’t really pertain to the restriction rules above and can be used in conjunction with the access modifiers above.

Static:

  • methods can only have access to other static methods and fields of the class

Final:

  • used to create constant variables
  • prevent method overriding
  • prevent inheritance

quangtn0018

Just my findings and techniques that I’ve learned from working and doing side projects on all things software engineering related

Quang Nguyen

Written by

Software Engineer

quangtn0018

Just my findings and techniques that I’ve learned from working and doing side projects on all things software engineering related

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade