Fiveable
Fiveable

public

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.

Analogy

Think of public access as a public park. Just like how anyone can enter and use the facilities in a public park, public members can be accessed and used by any part of the program.

Related terms

Private: 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.

"public" appears in:

Subjects (1)

Practice Questions (19)

collegeable - rocket pep

Are you a college student?

  • Study guides for the entire semester

  • 200k practice questions

  • Glossary of 50k key terms - memorize important vocab



© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.

AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.