Java Reference
In-Depth Information
E
Java Modifiers
This appendix summarizes the modifiers that give particular characteristics to Java
classes, interfaces, methods, and variables. For discussion purposes, the set of all
Java modifiers is divided into two groups: visibility modifiers and all others.
Java Visibility Modifiers
The table in Figure E.1 describes the effect of Java visibility modifiers on various
constructs. Visibility modifiers operate in the same way on classes and interfaces
and in the same way on methods and variables.
Default visibility means that no visibility modifier was explicitly used. Default
visibility is sometimes called package visibility, but you cannot use the reserved
word package as a modifier.
Note that only inner classes can have private or protected visibility.
Modifier
Classes and interfaces
Methods and variables
default (no modifier)
Visible in its package.
Visible to any class in the same package
as its class.
public
Visible anywhere.
Visible anywhere.
protected
Can only be applied to inner classes.
Visible in its package and to classes that
extend the class in which it is declared.
Visible to any class in the same package
and to any derived classes.
private
Can only be applied to inner classes.
Visible to the enclosing class only.
Not visible by any other class.
FIGURE E.1 Java visibility modifiers
683
 
Search WWH ::




Custom Search