Java Reference
In-Depth Information
A PPENDIX D
Java Modifiers
Modifiers are used on classes and class members (constructors, methods, data, and class-level
blocks), but the final modifier can also be used on local variables in a method. A modifier
that can be applied to a class is called a class modifier . A modifier that can be applied to a
method is called a method modifier . A modifier that can be applied to a data field is called a
data modifier . A modifier that can be applied to a class-level block is called a block modifier .
The following table gives a summary of the Java modifiers.
Modifier
Class
Constructor
Method
Data
Block
Explanation
(default) *
A class, constructor, method,
or data field is visible in this
package.
U
U
U
U
U
A class, constructor, method,
or data field is visible to all the
programs in any package.
public
U
U
U
U
private
U
U
U
A constructor, method, or data
field is only visible in this class.
protected
A constructor, method, or data
field is visible in this package
and in subclasses of this class in
any package.
U
U
U
static
U
U
U
Define a class method, a class
data field, or a static initializa-
tion block.
final
U
U
U
A final class cannot be
extended. A final method cannot
be modified in a subclass.
A final data field is a constant.
An abstract class must be
extended. An abstract method
must be implemented in a con-
crete subclass.
abstract
U
U
native
A native method indicates that
the method is implemented
using a language other than
Java.
U
* Default access doesn't have a modiier associated with it. For example: class Test {}
1270
 
 
 
 
Search WWH ::




Custom Search