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.

CLASSES Class Body and Member Declarations 8.1.6<br />

public ??? getNumberOfScales() { return 91; }<br />

}<br />

It is impossible to declare a method named getNumberOfScales whose signature<br />

and return type are compatible with those of both the methods declared in interface<br />

Fish and in interface StringBass, because a class cannot have multiple<br />

methods with the same signature and different primitive return types (§8.4).<br />

<strong>The</strong>refore, it is impossible for a single class to implement both interface Fish and<br />

interface StringBass (§8.4.8).<br />

A class may not at the same time be a subtype of two interface types which<br />

are different invocations of the same generic interface (§9.1.2), or an invocation of<br />

a generic interface and a raw type naming that same generic interface.<br />

DISCUSSION<br />

Here is an example of an illegal multiple inheritance of an interface:<br />

class B implements I<br />

class C extends B implements I<br />

This requirement was introduced in order to support translation by type erasure (§4.6).<br />

8.1.6 Class Body and Member Declarations<br />

A class body may contain declarations of members of the class, that is, fields<br />

(§8.3), classes (§8.5), interfaces (§8.5) and methods (§8.4). A class body may also<br />

contain instance initializers (§8.6), static initializers (§8.7), and declarations of<br />

constructors (§8.8) for the class.<br />

ClassBody:<br />

{ ClassBodyDeclarationsopt }<br />

ClassBodyDeclarations:<br />

ClassBodyDeclaration<br />

ClassBodyDeclarations ClassBodyDeclaration<br />

ClassBodyDeclaration:<br />

ClassMemberDeclaration<br />

InstanceInitializer<br />

StaticInitializer<br />

ConstructorDeclaration<br />

DRAFT<br />

189

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

Saved successfully!

Ooh no, something went wrong!