Subclasses, Superclasses, and Inheritance

When you write your first object-oriented program, you do not have to begin your real-world modeling from scratch. REXX has done some of this up-front work for you, providing predefined classes and methods. From there you can create additional classes and methods of your own, as you need them.

REXX classes are hierarchical. Any subclass (classes below a class in the hierarchy) will inherit, or be able to use, the methods and variables of one or more superclasses (classes above a class in the hierarchy).
Superclass and subclasses

Superclass

┌─────────────┼─────────────┐
│ │ │
Subclass Subclass Subclass

You can add a class to an existing superclass. For example, you might add the Icon class to the Screen-Object superclass:
The Screen-Object superclass

Screen-Object class

┌─────────────┼─────────────┐
│ │ │
Icon class Window class Bitmap class

Doing this lets the subclass inherit additional methods from the superclass. Sometimes a class may have more than one superclass. (Subclass Bitmap might have superclasses Screen-Object and Art-Object.) Acquiring methods and variables from more than one superclass is known as multiple inheritance.
Multiple inheritance

Screen-Object Art-Object
│ │
┌─────────────┼─────────────┐ │
│ │ │ │
Icon Window Bitmap


[Back: Data Abstraction]
[Next: The Basics of Classes]