Inheritance, Polymorphism, and Interfaces
So far in our journey of object-oriented design and C++, we have focused on abstraction and data encapsulation. We will now turn our attention to inheritance and polymorphism. What is inheritance? What is polymorphism? Why do we need it? Consider the following three objects:
Figure 2B.1: Vehicle objects
In the preceding diagram, we can see that there are three very different objects. They have some things in common. They all have wheels (a different number), an engine (different size, power, or configuration), start engine, drive, apply brakes, stop engine, and so on, using which we can do something.
So, we can abstract them into something called a vehicle that demonstrates these attributes and general behaviors. If we express this as a C++ class, it might look like the following:
class Vehicle
{
public:
  Vehicle() = default;
  Vehicle(int numberWheels, int engineSize) :
        ...