2.4 Class Hierarchies2.3 Superclasses and Subclasses2 Java with Caffeine2.5 Interface Hierarchies

2.4 Class Hierarchies

Returning to our example, we can define a subclass CD of Article which adds other fields and methods.

   class CD extends Article
   {
     String interpreter;
     String[] songs;

     CD(...) { ... }

     String getInterpreter() { ... }
     String[] getSongs() { ... }
   }

Further on, we may create subclasses of Book like Hardcover and Paperback and construct a hierarchy as the one shown in the following figure:


A

A Class Diagram
 


In this  class diagram superclasses and subclasses are organized in a tree where arrows are used to denote the relationship from the subclass to a superclass.

If a class is not explicitly derived from another class, it is implicitly considered as a subclass of the predefined class Object. All classes are therefore directly or indirectly derived from Object. We will discuss this class in more detail later.


© Wolfgang Schreiner; February 3, 2005

2.4 Class Hierarchies2.3 Superclasses and Subclasses2 Java with Caffeine2.5 Interface Hierarchies