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.

CLASSES Method Modifiers 8.4.3<br />

an implementation. <strong>The</strong> declaration of an abstract method m must appear<br />

directly within an abstract class (call it A) unless it occurs within an enum<br />

(§8.9); otherwise a compile-time error results. Every subclass of A that is not<br />

abstract must provide an implementation for m, or a compile-time error occurs<br />

as specified in §8.1.1.1.<br />

It is a compile-time error for a private method to be declared abstract.<br />

It would be impossible for a subclass to implement a private abstract<br />

method, because private methods are not inherited by subclasses; therefore such<br />

a method could never be used.<br />

It is a compile-time error for a static method to be declared abstract.<br />

It is a compile-time error for a final method to be declared abstract.<br />

An abstract class can override an abstract method by providing another<br />

abstract method declaration.<br />

This can provide a place to put a documentation comment, to refine the return<br />

type, or to declare that the set of checked exceptions (§11.2) that can be thrown by<br />

that method, when it is implemented by its subclasses, is to be more limited. For<br />

example, consider this code:<br />

class BufferEmpty extends Exception {<br />

BufferEmpty() { super(); }<br />

BufferEmpty(String s) { super(s); }<br />

}<br />

class BufferError extends Exception {<br />

BufferError() { super(); }<br />

BufferError(String s) { super(s); }<br />

}<br />

public interface Buffer {<br />

char get() throws BufferEmpty, BufferError;<br />

}<br />

public abstract class InfiniteBuffer implements Buffer {<br />

public abstract char get() throws BufferError;<br />

}<br />

DRAFT<br />

<strong>The</strong> overriding declaration of method get in class InfiniteBuffer states<br />

that method get in any subclass of InfiniteBuffer never throws a Buffer-<br />

Empty exception, putatively because it generates the data in the buffer, and thus<br />

can never run out of data.<br />

An instance method that is not abstract can be overridden by an abstract<br />

method.<br />

215

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

Saved successfully!

Ooh no, something went wrong!