Access Modifiers

The purpose of access modifiers is to find which objects have access to your object's methods (or data members). In general, you want to provide public interfaces to your private data, while making most of your methods that do real work, as well as your data, private. There are times when other options might be desirable. For example, you might allow the classes in your package to have access to your methods. In this case, you might give them package-level access. Or, you might want all the classes of your package, and any subclasses in any other packages, to have access to your methods, an essential ingredient of inheritance by those subclasses. In that case, you might make your classes protected. For well-encapsulated classes, ...

Get PURE Java™ 2 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.