Java Reference
In-Depth Information
4.4.4
interfaces are abstract classes
Because an interface is an abstract class, all the rules of inheritance apply.
Specifically,
1.
The
IS-A
relationship holds. If class
C
implements interface
I
,
then
C IS-A I
and is type-compatible with
I
. If a class
C
implements
interfaces
I
1
,
I
2
, and
I
3
, then
C IS-A I
1
,
C IS-A I
2
, and
C IS-A I
3
,
and is type-compatible with
I
1
,
I
2
, and
I
3
.
2.
The
instanceof
operator can be used to determine if a reference is
type-compatible with an interface.
3.
When a class implements an interface method, it may not reduce
visibility. Since all interface methods are public, all implementations
must be public.
4.
When a class implements an interface method, it may not add checked
exceptions to the
throws
list. If a class implements multiple interfaces in
which the same method occurs with a different
throws
list, the
throws
list
of the implementation may list only checked exceptions that are in the
intersection of the
throws
lists of the interface methods.
5.
When a class implements an interface method, it must implement the
exact signature (not including the
throws
list); otherwise, it inherits an
abstract version of the interface method and has provided a non-
abstract overloaded, but different, method.
6.
A class may not implement two interfaces that contain a method with
the same signature and incompatible return types, since it would be
impossible to provide both methods in one class.
7.
If a class fails to implement any methods in an interface, it must be
declared abstract.
8.
Interfaces can extend other interfaces (including multiple interfaces).
fundamental inheritance in java
4.5
Two important places where inheritance is used in Java are the
Object
class
and the hierarchy of exceptions.
4.5.1
the
Object
class
Java specifies that if a class does not extend another class, then it implicitly
extends the class
Object
(defined in
java.lang
). As a result, every class is
either a direct or indirect subclass of
Object
.
Search WWH ::
Custom Search