Access Modifiers

Access modifiers are an important part of any declaration that can be accessed outside the class or package in which it is made. Access modifiers enable you to determine whether a declaration is limited to a particular class, a class and its subclasses, a package, or if it is freely accessible. Although access modifiers are not ironclad security controls, they can be used to limit access to your classes, interfaces, variables, methods, and constructors.

Java provides three access modifiers (public, protected, and private) and a fourth default access (package access). These modifiers are used as follows:

  • public. Enables a class or interface to be accessed outside of its package. It also enables a variable, method, or constructor ...

Get Sun Certification Training Guide (310-025, 310-027): Java™ 2 Programmer and Developer Exams 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.