Examine the example program named INHERIT6.CPP for yet another variation to our basic program, this time adding constructors.

The vehicle class has a constructor to initialize the number of wheels and the weight to the indicated values and has no surprising constructs. The car and truck classes each have a constructor also to initialize their unique variables to some unique values. If you jump ahead to the main program, you will find that the initializing statements are commented out for each of the objects so we must depend on the constructors to initialize the variables. The most important thing to glean from this example program is the fact that when one of the constructors is called for a derived class, the constructor is also called for the parent class. In fact, the constructor for the parent class will be called before the constructor for the derived class is called. All of the data will be initialized, including the data inherited from the parent class.

We will say much more about constructors used with inheritance in the next chapter of this tutorial. Be sure to compile and execute this example program.