Java Reference
In-Depth Information
It is a compile-time error if a method declared in an interface is declared
final
. However, a
method declared in an interface may be implemented by a method that is declared
final
in a
class that implements the interface.
It is a compile-time error for the body of an interface to declare, explicitly or implicitly,
two methods with override-equivalent signatures (§
8.4.2
).
However, an interface may inherit several methods with such signatures (§
9.4.1
).
A method in an interface may be generic. The rules for type parameters of a generic method
9.4.1. Inheritance and Overriding
An interface inherits from its direct superinterfaces all methods of the superinterfaces that
are not overridden by a declaration in the interface.
Methods are overridden on a signature-by-signature basis.
and a subinterface overrides one of them, the subinterface still inherits the other meth-
od.
9.4.1.1. Overriding (by Instance Methods)
An instance method
m
1
declared in an interface
I
overrides another instance method,
m
2
,
declared in interface
J
iff both of the following are true:
•
I
is a subinterface of
J
.
Example 9.4.1.1-1. Overriding an
abstract
Method Declaration
Methods declared in interfaces are
abstract
and thus contain no implementation. About
all that can be accomplished by an overriding method declaration, other than to affirm
a method signature, is to refine the return type or to restrict the exceptions that might
be thrown by an implementation of the method. Here is a variation of the example
shown in (§
8.4.3.1
):
class BufferEmpty extends Exception {}
class BufferException extends Exception {}
interface Buffer {
char get() throws BufferEmpty, BufferException;