In this recipe, you will learn about two important OOD concepts, namely Inheritance and Polymorphism, which have been mentioned already and used in the examples of the previous recipes.
Inheritance is the ability of one class to extend (and, optionally, override) the properties and/or methods of another class. The extended class is called the base class, superclass, or parent class. The new extension of the class is called a subclass or child class.
Note
Polymorphism is the ability to use the base class as a type for the references to the objects of its subclasses.
To demonstrate the power of these two concepts, let's create classes that represent cars and trucks, each having weight, engine power, and speed it can reach (as a function of time) with maximum load. In addition, a car, in this case, will be characterized by the number of passengers, while a truck's important feature will be its payload.