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.

8.1.1 Class Modifiers CLASSES<br />

176<br />

If two or more class modifiers appear in a class declaration, then it is customary,<br />

though not required, that they appear in the order consistent with that shown<br />

above in the production for ClassModifier.<br />

8.1.1.1 abstract Classes<br />

An abstract class is a class that is incomplete, or to be considered incomplete.<br />

Normal classes may have abstract methods (§8.4.3.1, §9.4), that is methods<br />

that are declared but not yet implemented, only if they are abstract classes.<br />

If a normal class that is not abstract contains an abstract method, then a compile-time<br />

error occurs.<br />

Enum types (§8.9) must not be declared abstract; doing so will result in a<br />

compile-time error. It is a compile-time error for an enum type E to have an<br />

abstract method m as a member unless E has one or more enum constants, and all<br />

of E’s enum constants have class bodies that provide concrete implementations of<br />

m. It is a compile-time error for the class body of an enum constant to declare an<br />

abstract method.<br />

A class C has abstract methods if any of the following is true:<br />

• C explicitly contains a declaration of an abstract method (§8.4.3).<br />

• Any of C’s superclasses has an abstract method and C neither declares nor<br />

inherits a method that implements (§8.4.8.1) it.<br />

• A direct superinterface (§8.1.5) of C declares or inherits a method (which is<br />

therefore necessarily abstract) and C neither declares nor inherits a method<br />

that implements it.<br />

In the example:<br />

DRAFT<br />

abstract class Point {<br />

int x = 1, y = 1;<br />

void move(int dx, int dy) {<br />

x += dx;<br />

y += dy;<br />

alert();<br />

}<br />

abstract void alert();<br />

}<br />

abstract class ColoredPoint extends Point {<br />

int color;<br />

}

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

Saved successfully!

Ooh no, something went wrong!