O'Reilly logo

PURE Java™ 2 by Kenneth Litwak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required