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.
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.
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.
© 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.