Class Inheritance

Preface: We wish to examine the process of class inheritance as implemented in the Java language. The best way to do this is by studying an example. We have chosen to use our "Shapes" library as an example, looking carefully at the relationships between a Square, which is a subclass of a Rectangle, which itself is a subclass of a FilledShape (which in turn, is a subclass of a Shape, ...)

Reading: Our textbook introduces these same concepts in Ch. 4. They give brief discussion of the Square/Rectangle interplay in Section 4.3.2 (though our class definitions vary slightly from theirs). Most of the discussion in Ch 4 relies on examples drawn from Java's Abstract Windowing Toolkit (AWT), which includes classes used for developing graphical interfaces for programs. For now, we will not directly address these aspects of Java's AWT (though we may go back and do so later in the course). In any event, you may wish to skim Ch. 4.1-4.3 of the text with an eye towards issues of class inheritance. You should certainly review the Java Language Summary near the end of Ch. 4.

Our Example: We will examine in detail the source code being used to define the two classes Rectangle and Square drawn from our csa120.shape package. Also of interest are an updated UML diagram detailing the relevant part of the class hierarchy, as well as the formal documentation for the Rectangle and Square classes.

A brief outline of the major points we will address follows:


Michael Goldwasser
Last modified: Wednesday, 25 February 2004