Java Reference
In-Depth Information
Chapter 8. Classes
Class declarations define new reference types and describe how they are implemented
8.1 ) .
A top level class is a class that is not a nested class.
A nested class is any class whose declaration occurs within the body of another class or in-
terface.
This chapter discusses the common semantics of all classes - top level (§ 7.6 ) and nested
(including member classes (§ 8.5 , § 9.5 ) , local classes (§ 14.3 ) and anonymous classes
15.9.5 ) ). Details that are specific to particular kinds of classes are discussed in the sections
dedicated to these constructs.
A named class may be declared abstract 8.1.1.1 ) and must be declared abstract if it is in-
completely implemented; such a class cannot be instantiated, but can be extended by sub-
classes. A class may be declared final 8.1.1.2 ), in which case it cannot have subclasses. If
a class is declared public , then it can be referred to from other packages. Each class except
Object is an extension of (that is, a subclass of) a single existing class (§ 8.1.4 ) and may im-
plement interfaces (§ 8.1.5 ) . Classes may be generic 8.1.2 ) , that is, they may declare type
variables whose bindings may differ among different instances of the class.
Classes may be decorated with annotations (§ 9.7 ) just like any other kind of declaration.
The body of a class declares members (fields and methods and nested classes and interfaces),
instance and static initializers, and constructors (§ 8.1.6 ) . The scope (§ 6.3 ) of a member
8.2 ) is the entire body of the declaration of the class to which the member belongs. Field,
method, member class, member interface, and constructor declarations may include the ac-
cess modifiers (§ 6.6 ) public , protected , or private . The members of a class include both declared
and inherited members (§ 8.2 ). Newly declared fields can hide fields declared in a superclass
or superinterface. Newly declared class members and interface members can hide class or
interface members declared in a superclass or superinterface. Newly declared methods can
hide, implement, or override methods declared in a superclass or superinterface.
Field declarations (§ 8.3 ) describe class variables, which are incarnated once, and instance
variables, which are freshly incarnated for each instance of the class. A field may be declared
final 8.3.1.2 ), in which case it can be assigned to only once. Any field declaration may in-
clude an initializer.
Search WWH ::




Custom Search