CLASSES
Superinterfaces
8.1.4
Thus, the example:
interface Colorable {
void setColor(int color);
int getColor();
}
class Point { int x, y; };
class ColoredPoint extends Point implements Colorable {
int color;
}
causes a compile time error, because
ColoredPoint
is not an
abstract
class but
it fails to provide an implementation of methods
setColor
and
getColor
of the
interface
Colorable
.
It is permitted for a single method declaration in a class to implement methods
of more than one superinterface. For example, in the code:
interface Fish { int getNumberOfScales(); }
interface Piano { int getNumberOfScales(); }
class Tuna implements Fish, Piano {
//
You can tune a piano, but can you tuna fish?
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
with the same
signature and return type as those of both the methods declared in interface
Fish
and in interface
StringBass
, because a class can have only one method with a
given signature ( 8.4). Therefore, it is impossible for a single class to implement
both interface
Fish
and interface
StringBass
( 8.4.6).
137
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Inexpensive Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Jsp Hosting
Cheap Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved