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 Superinterfaces 8.1.5<br />

results in a compile-time error because the names java.lang.Cloneable and<br />

Cloneable refer to the same interface.<br />

An interface type I is a superinterface of class type C if any of the following<br />

is true:<br />

• I is a direct superinterface of C.<br />

• C has some direct superinterface J for which I is a superinterface, using the<br />

definition of “superinterface of an interface” given in §9.1.3.<br />

• I is a superinterface of the direct superclass of C.<br />

A class is said to implement all its superinterfaces.<br />

In the example:<br />

public interface Colorable {<br />

void setColor(int color);<br />

int getColor();<br />

}<br />

public enum Finish {MATTE, GLOSSY}<br />

public interface Paintable extends Colorable {<br />

void setFinish(Finish finish);<br />

Finish getFinish();<br />

}<br />

class Point { int x, y; }<br />

class ColoredPoint extends Point implements Colorable {<br />

int color;<br />

public void setColor(int color) { this.color = color; }<br />

public int getColor() { return color; }<br />

}<br />

class PaintedPoint extends ColoredPoint implements Paintable<br />

{<br />

Finish finish;<br />

public void setFinish(Finish finish) {<br />

this.finish = finish;<br />

}<br />

public Finish getFinish() { return finish; }<br />

}<br />

the relationships are as follows:<br />

• <strong>The</strong> interface Paintable is a superinterface of class PaintedPoint.<br />

• <strong>The</strong> interface Colorable is a superinterface of class ColoredPoint and of<br />

class PaintedPoint.<br />

DRAFT<br />

187

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

Saved successfully!

Ooh no, something went wrong!