Notes on Generics and Inheritance
Generics can be used with inheritance in several ways:
- A generic class can be derived from a non-generic class. For example, class object (which is not a generic class) is a direct or indirect base class of every generic class.
- A generic class can be derived from another generic class. Recall that in Chapter 25, the non-generic Stack class (Fig. 25.12) inherits from the non-generic List class (Fig. 25.5). You could also create a generic Stack class by inheriting from a generic List class.
- A non-generic class can be derived from a generic class. For example, you can implement a non-generic AddressList class that inherits from a generic List class and stores only Address objects.