← Back to Question List
C++ Code Walkthrough #73
Three Levels of Construction and Destruction
📄 Code
Read carefully — what does this print?1#include <iostream>2using namespace std;34class Vehicle {5public:6 Vehicle() { cout << "Vehicle" << endl; }7 ~Vehicle() { cout << "~Vehicle" << endl; }8};910class Car : public Vehicle {11public:12 Car() { cout << "Car" << endl; }13 ~Car() { cout << "~Car" << endl; }14};1516class Taxi : public Car {17public:18 Taxi() { cout << "Taxi" << endl; }19 ~Taxi() { cout << "~Taxi" << endl; }20};2122int main() {23 Taxi t;24 cout << "---" << endl;25 Car c;26 cout << "---" << endl;27 return 0;28}