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.4.8 Inheritance, Overriding, and Hiding CLASSES<br />

228<br />

String id(String x) {...}<br />

Integer id(Integer x) {...}<br />

}<br />

This is also illegal, since D.id(String) is a member of D, D.id(Integer) is<br />

declared in D and:<br />

• the two methods have the same name, id<br />

• the two methods have different signatures.<br />

• D.id(Integer) is accessible to D<br />

• D.id(String) overrides C.id(String) and D.id(Integer) overrides<br />

I.id(Integer) yet the two overridden methods have the same erasure<br />

<strong>The</strong> access modifier (§6.6) of an overriding or hiding method must provide at<br />

least as much access as the overridden or hidden method, or a compile-time error<br />

occurs. In more detail:<br />

• If the overridden or hidden method is public, then the overriding or hiding<br />

method must be public; otherwise, a compile-time error occurs.<br />

• If the overridden or hidden method is protected, then the overriding or hiding<br />

method must be protected or public; otherwise, a compile-time error<br />

occurs.<br />

• If the overridden or hidden method has default (package) access, then the<br />

overriding or hiding method must not be private; otherwise, a compile-time<br />

error occurs.<br />

Note that a private method cannot be hidden or overridden in the technical<br />

sense of those terms. This means that a subclass can declare a method with the<br />

same signature as a private method in one of its superclasses, and there is no<br />

requirement that the return type or throws clause of such a method bear any relationship<br />

to those of the private method in the superclass.<br />

DRAFT<br />

8.4.8.4 Inheriting Methods with Override-Equivalent Signatures<br />

It is possible for a class to inherit multiple methods with override-equivalent<br />

(§8.4.2) signatures.<br />

It is a compile time error if a class C inherits a concrete method whose signatures<br />

is a subsignature of another concrete method inherited by C.

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

Saved successfully!

Ooh no, something went wrong!