Your task is to define two classes:
- Base class:
Vehicle - Derived class:
Car (inherits publicly from Vehicle)- A method
void printCar() that prints:
Car Vehicle
The program will:
- Create a
Car object. - Call
printCategory() (inherited from base). - Call
printCar() (defined in derived).
Example
Output:
Generic Vehicle
Car Vehicle
Why this output?
- The base class method printCategory() is accessible through the derived class because of public inheritance.
- The derived class adds its own method printCar() and prints its message.
Question Significance
This reinforces the idea of reusing base functionality and extending it in derived classes.