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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

8.4.8 Inheritance, Overriding, and Hiding CLASSES<br />

224<br />

Note that it is possible for a method to have a declared return type and yet<br />

contain no return statements. Here is one example:<br />

class DizzyDean {<br />

int pitch() { throw new RuntimeException("90 mph?!"); }<br />

}<br />

8.4.8 Inheritance, Overriding, and Hiding<br />

A class C inherits from its direct superclass and direct superinterfaces all non-private<br />

methods (whether abstract or not) of the superclass and superinterfaces<br />

that are public, protected or declared with default access in the same package as C<br />

and are neither overridden (§8.4.8.1) nor hidden (§8.4.8.2) by a declaration in the<br />

class.<br />

8.4.8.1 Overriding (by Instance Methods)<br />

An instance method m1 declared in a class C overrides another instance method,<br />

m2, declared in class A iff all of the following are true:<br />

1. C is a subclass of A.<br />

2. <strong>The</strong> signature of m1 is a subsignature (§8.4.2) of the signature of m2.<br />

3. Either<br />

◆ m2 is public, protected or declared with default access in the same package<br />

as C, or<br />

◆ m1 overrides a method m3, m3 distinct from m1, m3 distinct from m2, such<br />

that m3 overrides m2.<br />

Moreover, if m1 is not abstract, then m1 is said to implement any and all declarations<br />

of abstract methods that it overrides.<br />

DISCUSSION<br />

DRAFT<br />

<strong>The</strong> signature of an overriding method may differ from the overridden one if a formal<br />

parameter in one of the methods has raw type, while the corresponding parameter in the<br />

other has a parameterized type.<br />

<strong>The</strong> rules allow the signature of the overriding method to differ from the overridden<br />

one, to accommodate migration of pre-existing code to take advantage of genericity. See<br />

section §8.4.2 for further analysis.

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

Saved successfully!

Ooh no, something went wrong!