Next: 3.5 Packages
Up: 3. Yet Another Object Notation
Previous: 3.3 Optional Clientship Annotations
Subsections
Inheritance is a mechanism from which one class (the subclass), is
said to inherit variables and methods from another class
(the superclass).
As Java has only single inheritance, the class hierarchy
conforms to a tree. The notation for the inheritance is in figure
19.
Figure 19:
Inheritance
 |
An interface, like a class, is a mechanism to declare final
variables and methods. An interface looks a lot like an abstract
class, except that it uses the keyword interface instead of the
words abstract and class. All the methods defined within an
interface are implicit. A further restriction is that variables
declared in interfaces must be either static or final, i.e. constants. A class implements an interface by providing
an implementation (i.e. a body) for all the abstract methods of
the interface. Therefore the declaration of methods is done in
the interface and the implementation is done in the class (or
classes) that implement this interface. This is shown in figure
20. A class Subclass inherits from class
Superclass and implements interface interface.
Figure 20:
Interfaces
 |