Vehicle Inheritance Public

#include <iostream>
using namespace std;

class Vehicle {
public:
    void printCategory(){printf("Generic Vehicle\n");} 
};

// your code here: define class Car inheriting publicly from Vehicle
// implement void printCar() to print "Car Vehicle"
class Car : public Vehicle{
    public:
    void printCar(){printf("Car Vehicle");}
};
int main() {
    Car c;
    c.printCategory(); // inherited method
    c.printCar();      // derived method
    return 0;
}
Upvote
Downvote
Loading...

Input

Expected Output

Generic Vehicle Car Vehicle