fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. class Vehicle{
  4. protected:
  5. string model;
  6. public:
  7. Vehicle() = default;
  8. Vehicle(string model){
  9. this->model = model;
  10. cout << "Vehicle Constructor Called\n";
  11. }
  12. };
  13. class Four_Wheeler : public Vehicle{
  14. protected:
  15. string trunk_type;
  16. public:
  17. Four_Wheeler() = default;
  18. Four_Wheeler(string model, string trunk_type) : Vehicle(model), trunk_type(trunk_type){
  19. cout << "Four-Wheeler Constructor Called\n";
  20. }
  21. };
  22. class Car : public Four_Wheeler{
  23. protected:
  24. int trunk_capacity;
  25. public:
  26. Car() = default;
  27. Car(string model, string trunk_type, int trunk_capacity) : Four_Wheeler(model, trunk_type), trunk_capacity(trunk_capacity){
  28. cout << "Car Constructor Called!\n";
  29. }
  30. };
  31. int main(){
  32. Four_Wheeler fw("GTR", "Small");
  33. Car("BMW", "Small", 8);
  34. return 0;
  35. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Vehicle Constructor Called
Four-Wheeler Constructor Called
Vehicle Constructor Called
Four-Wheeler Constructor Called
Car Constructor Called!