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
in an interface are the same as for a generic method in a class (§ 8.4.4 ) .
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.
If, for example, an interface declares two public methods with the same name (§ 9.4.2 ) ,
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 .
• The signature of m 1 is a subsignature (§ 8.4.2 ) of the signature of m 2 .
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 ):
Click here to view code image
class BufferEmpty extends Exception {}
class BufferException extends Exception {}
interface Buffer {
char get() throws BufferEmpty, BufferException;
Search WWH ::




Custom Search