All submissions

Vehicle Inheritance Public

#include <iostream>
using namespace std;

class Vehicle {
public:
    // your code here: implement void printCategory() to print "Generic Vehicle"
    void printCategory(void) {
        cout << "Generic Vehicle" << endl;
    }
};

// your code here: define class Car inheriting publicly from Vehicle
class Car : public Vehicle {
public:
    void printCar(void) {
        cout << "Car Vehicle" << endl;
    }
};
// implement void printCar() to print "Car Vehicle"

int main() {
    Car c;
    c.printCategory(); // inherited method
    c.printCar();      // derived method
    return 0;
}
Loading...

Input

Expected Output

Generic Vehicle Car Vehicle