Java Reference
In-Depth Information
interfaces it implements or the class it extends, and simple references
to multiply-inherited non-hidden fields will be ambiguous.
4.3.2. Inheriting, Overriding, and Overloading Methods
A subinterface inherits all the methods declared in its superinterfaces.
If a declared method in a subinterface has the same signature (name
and parameter list) as an inherited method and the same, or covariant,
return type, then the new declaration overrides any and all existing de-
clarations. Overriding in interfaces, unlike overriding in classes, has no
semantic effectthe interface effectively contains multiple declarations of
the same method, but in any one implementing class there can only be
one implementation of that method.
Similarly, if an interface inherits more than one method with the same
signature, or if a class implements different interfaces containing a
method with the same signature, there is only one such method. The
implementation of this method is ultimately defined by the class imple-
menting the interfaces, and there is no ambiguity there. If the meth-
ods have the same signature but different return types, then one of the
return types must be a subtype of all the others, otherwise a compile-
time error occurs. The implementation must define a method that re-
turns that common subtype.
The real issue is whether a single implementation of the method can
honor all the contracts implied by that method being part of the different
interfaces. This may be an impossible requirement to satisfy in some
circumstances. For example:
interface CardDealer {
void draw(); // flip top card
void deal(); // distribute cards
void shuffle();
}
interface GraphicalComponent {
void draw(); // render on default device
void draw(Device d); // render on 'd'
void rotate(int degrees);
 
Search WWH ::




Custom Search