CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List
C++ Code Walkthrough #69

Base Before Derived, Derived Before Base

easyInheritance

📄 Code

Read carefully — what does this print?
1#include <iostream>
2using namespace std;
3 
4class Animal {
5public:
6 Animal() { cout << "Animal()" << endl; }
7 ~Animal() { cout << "~Animal()" << endl; }
8};
9 
10class Dog : public Animal {
11public:
12 Dog() { cout << "Dog()" << endl; }
13 ~Dog() { cout << "~Dog()" << endl; }
14};
15 
16int main() {
17 cout << "start" << endl;
18 {
19 Dog d;
20 cout << "have a dog" << endl;
21 }
22 cout << "end" << endl;
23 return 0;
24}

🎯 Your Answer