10.12.2012 Views

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

The Java Language Specification, Third Edition

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER8<br />

Classes<br />

Origins: A Short Etymological Dictionary of Modern English<br />

CLASS declarations define new reference types and describe how they are<br />

implemented (§8.1).<br />

A nested class is any class whose declaration occurs within the body of<br />

another class or interface. A top level class is a class that is not a nested class.<br />

This chapter discusses the common semantics of all classes—top level (§7.6)<br />

and nested (including member classes (§8.5, §9.5), local classes (§14.3) and anonymous<br />

classes (§15.9.5)). Details that are specific to particular kinds of classes are<br />

discussed in the sections dedicated to these constructs.<br />

A named class may be declared abstract (§8.1.1.1) and must be declared<br />

abstract if it is incompletely implemented; such a class cannot be instantiated,<br />

but can be extended by subclasses. A class may be declared final (§8.1.1.2), in<br />

which case it cannot have subclasses. If a class is declared public, then it can be<br />

referred to from other packages. Each class except Object is an extension of (that<br />

is, a subclass of) a single existing class (§8.1.4) and may implement interfaces<br />

(§8.1.5). Classes may be generic, that is, they may declare type variables (§4.4)<br />

whose bindings may differ among different instances of the class.<br />

Classes may be decorated with annotations (§9.7) just like any other kind of<br />

declaration.<br />

<strong>The</strong> body of a class declares members (fields and methods and nested classes<br />

and interfaces), instance and static initializers, and constructors (§8.1.6). <strong>The</strong><br />

scope (§6.3) of a member (§8.2) is the entire body of the declaration of the class to<br />

DRAFT<br />

173

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!