Written by the Fiveable Content Team โข Last updated September 2025
Verified for the 2026 exam
Verified for the 2026 examโขWritten by the Fiveable Content Team โข Last updated September 2025
Definition
Public is an access modifier in Java that indicates unrestricted visibility for classes, methods, and variables. Public members can be accessed from any other class or package.
Private is an access modifier that restricts visibility to only within the same class. Private members cannot be accessed from outside the class.
Protected: Protected is an access modifier that allows visibility within the same package or subclasses. Protected members are not accessible from unrelated classes.
Default (package-private): Default, also known as package-private, is an access level without any keyword specified. It allows visibility within the same package but not outside of it.