Java: What do access levels mean?

What does it mean for a field or method to be able to have class, package, subclass, or world access?

I'm reading this page if that helps:

Examples would help. Thanks.

1 Answer

  • 7 years ago
    Favorite Answer

    Access levels control the visibility of a member; ie from where you can get to it. A "private" variable can only be accessed from methods inside that object. A public member can be seen anywhere in your application. There is also protected (for advanced use) and the default which is package (or any class in the same folder).

    In general, you want to use the lowest access level possible to keep your application from getting too complicated to read.

Still have questions? Get your answers by asking now.