Java Reference
In-Depth Information
// You can tune a piano, but can you tuna fish?
public int getNumberOfScales() { return 91; }
}
the method
getNumberOfScales
in class
Tuna
has a name, signature, and return type that
matches the method declared in interface
Fish
and also matches the method declared
in interface
Piano
; it is considered to implement both.
On the other hand, in a situation such as this:
interface Fish { int getNumberOfScales(); }
interface StringBass { double getNumberOfScales(); }
class Bass implements Fish, StringBass {
// This declaration cannot be correct,
// no matter what type is used.
public ?? getNumberOfScales() { return 91; }
}
it is impossible to declare a method named
getNumberOfScales
whose signature and re-
turn type are compatible with those of both the methods declared in interface
Fish
and
in interface
StringBass
, because a class cannot have multiple methods with the same
A class may not at the same time be a subtype of two interface types which are different
eric interface and a raw type naming that same generic interface, or a compile-time error
occurs.
Example 8.1.5-4. Illegal Multiple Inheritance of an Interface
interface I<T> {}
class B implements I<Integer> {}
class C extends B implements I<String> {}
8.1.6. Class Body and Member Declarations