next up previous contents
Next: 3.5 Packages Up: 3. Yet Another Object Notation Previous: 3.3 Optional Clientship Annotations

Subsections


3.4 Inheritance Relation

Inheritance is a mechanism from which one class (the subclass), is said to inherit variables and methods from another class (the superclass).

3.4.1 Single Inheritance

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
\begin{figure}
\begin{picture}
(350,230)(0,0)
%\graphpaper(0,0)(350,230)
\put...
...m} & \hspace*{2cm}\\
& \\ \hline
\end{tabular} }
\end{picture}
\end{figure}

3.4.2 Interfaces

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
\begin{figure}
\begin{picture}
(360,280)(0,0)
%\graphpaper(0,0)(360,280)
\put...
...\
& Method\_i() \\
& \\ \hline
\end{tabular} }
\end{picture}
\end{figure}