Java Reference
In-Depth Information
Example 8.1.5-1. Illegal Superinterfaces
Click here to view code image
class Redundant implements java.lang.Cloneable, Cloneable {
int x;
}
This program results in a compile-time error because the names java.lang.Cloneable and
Cloneable refer to the same interface.
An interface type I is a superinterface of class type C if any of the following is true:
I is a direct superinterface of C .
C has some direct superinterface J for which I is a superinterface, using the defini-
tion of “superinterface of an interface” given in § 9.1.3 .
I is a superinterface of the direct superclass of C .
A class can have a superinterface in more than one way.
A class is said to implement all its superinterfaces.
Example 8.1.5-2. Superinterfaces
Click here to view code image
interface Colorable {
void setColor(int color);
int getColor();
}
enum Finish { MATTE, GLOSSY }
interface Paintable extends Colorable {
void setFinish(Finish finish);
Finish getFinish();
}
class Point { int x, y; }
class ColoredPoint extends Point implements Colorable {
int color;
public void setColor(int color) { this.color = color; }
public int getColor() { return color; }
}
class PaintedPoint extends ColoredPoint implements Paintable {
Finish finish;
public void setFinish(Finish finish) {
this.finish = finish;
}
Search WWH ::




Custom Search