Start Coding Now

Access Modifiers in Java - Public, Private, Protected

Complete guide to access modifiers in Java. Understand the scope and visibility of classes, variables, and methods.

Access Levels

ModifierClassPackageSubclassWorld
publicYesYesYesYes
protectedYesYesYesNo
defaultYesYesNoNo
privateYesNoNoNo
Summary:
  • Private: Within class only.
  • Default (no modifier): Within package only.
  • Protected: Within package and outside package through inheritance.
  • Public: Everywhere.

Frequently Asked Questions