The following code snippet is from JLS 2nd edition, 8.4.3.1 abstract methods :
An abstract class can override an abstract method by providing another abstract method declaration.
This can provide a place to put a documentation comment, or to declare that the set of checked exceptions (�11.2) that can be thrown by that method, when it is implemented by its subclasses, is to be more limited. For example, consider this code:
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 abstract class InfiniteBuffer implements Buffer {
abstract char get() throws BufferError; <====
}
When I had a look at the above code, I was wondering how come
char get() method in abstract class can override (or say implement)
the method with default access as the method in interface Buffer
is implicitily public. To prove my assumption, I compiled the above code
and it complains about the accessibility modifiers.
Can anyone else explain, whether I'm missing anything else?