A Reader's Guide to Chapter 7

Mtht 420

What is Chapter 7 about? The introduction isn't very clear.

The basic idea of Chapter 7 is that if you have a class vaguely describing an object (take for example class Lego) you can create subclasses describing more explicit instances of that class (for example, class SpaceLego or class ThinLego.)

As you read the introduction, you may wish to keep the following example in mind. Suppose we have a class MovingObject which describes the bare basics of a moving object; its instance variables might be velocity and position. Its only methods might be constructors, get and set methods.

This class would be useful for describing baseballs, birds, and clouds, but would not be as useful for describing a car as the class Car we proposed in class week 10. However, we could create a class Car which extends class MovingObject, and which has instance variables describing maximum acceleration, number and list of passengers, etc. When we do this, we say that class Car is a subclass of class MovingObject, and that it inherits the properties (methods, instance variables, etc.) of class MovingObject. We could also say that class MovingObject is a (direct) superclass of class Car.

If we were writing code in which a lot of different cars appeared, we might even want to create subclasses of class Car: class PickupTruck, class MiniVan, class Sedan, and class SportsCar. These would be also be subclasses of class MovingObject, and would inherit the methods and instance variables of class MovingObject. We say that class Car is a direct superclass of class MiniVan, while class MovingObject is an indirect superclass.


MTHT 420