http://java.sun.com/docs/books/jls/second_edition/html/interfaces.doc.html
9.4.3 Examples of Abstract Method Declarations
The following examples illustrate some (possibly subtle) points about abstract method declarations.
9.4.3.1 Example: Overriding
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 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 {
BufferEmpty() { super(); }
BufferEmpty(String s) { super(s); }
}
class BufferError extends Exception {
BufferError() { super(); }
BufferError(String s) { super(s); }
}
public interface Buffer {
char get() throws BufferEmpty, BufferError;
}
public interface InfiniteBuffer extends Buffer {
char get() throws BufferError; // override
}
9.4.3.2 Example: Overloading
In the example code:
interface PointInterface {
void move(int dx, int dy);
}
interface RealPointInterface extends PointInterface {
void move(float dx, float dy);
void move(double dx, double dy);
}
the method name move is overloaded in interface RealPointInterface with three different signatures, two of them declared and one inherited. Any non-abstract class that implements interface RealPointInterface must provide implementations of all three method signatures.
'Java Programming' 카테고리의 다른 글
object reference 전달 (0) | 2009.06.04 |
---|---|
java heap space 늘리기 (0) | 2009.06.03 |
java enum (0) | 2009.06.01 |
Java Native Interface (0) | 2009.05.21 |
Log 출력(class name, line number) (0) | 2009.04.10 |