Java Reference
In-Depth Information
public Finish getFinish() { return finish; }
}
Here, the relationships are as follows:
• The interface Paintable is a superinterface of class PaintedPoint .
• The interface Colorable is a superinterface of class ColoredPoint and of class
PaintedPoint .
• The interface Paintable is a subinterface of the interface Colorable , and Colorable
is a superinterface of Paintable , as defined in § 9.1.3 .
The class PaintedPoint has Colorable as a superinterface both because it is a superinter-
face of ColoredPoint and because it is a superinterface of Paintable .
Unless the class being declared is abstract , the declarations of all the method members of
each direct superinterface must be implemented either by a declaration in this class or by
an existing method declaration inherited from the direct superclass, because a class that is
not abstract is not permitted to have abstract methods (§ 8.1.1.1 ) .
It is permitted for a single method declaration in a class to implement methods of more than
one superinterface.
Example 8.1.5-3. Implementing Methods of a Superinterface
Click here to view code image
interface Colorable {
void setColor(int color);
int getColor();
}
class Point { int x, y; };
class ColoredPoint extends Point implements Colorable {
int color;
}
This program causes a compile-time error, because ColoredPoint is not an abstract class
but fails to provide an implementation of methods setColor and getColor of the interface
Colorable .
In the following program:
Click here to view code image
interface Fish { int getNumberOfScales(); }
interface Piano { int getNumberOfScales(); }
class Tuna implements Fish, Piano {
Search WWH ::




Custom Search