4.7. Accessibility Modifiers for Top-level Classes and Interfaces

Top-level classes and interfaces within a package can be declared as public. This means that they are accessible from everywhere, both inside and outside of their package. If the accessibility modifier is omitted, then they are only accessible in the package and not in any other packages or subpackages. This is called package or default accessibility.

Accessibility modifiers for nested classes and interfaces are discussed in Section 7.1 on page 284.

Example 4.7. Accessibility Modifiers for Classes and Interfaces
 // File: Clown.java package wizard.pandorasBox; // (1) Package declaration import wizard.pandorasBox.artifacts.Ailment; // (2) Importing class public class Clown implements ...

Get Programmer's Guide to Java™ Certification, A: A Comprehensive Primer, Second Edition 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.