-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from rpandox/feat/mult-levl-iinheritance-q4
Feat/mult-levl-iinheritance-q4
- Loading branch information
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
// Base class | ||
class Base { | ||
public: | ||
Base() { | ||
cout << "Base class constructor called." << endl; | ||
} | ||
~Base() { | ||
cout << "Base class destructor called." << endl; | ||
} | ||
}; | ||
|
||
// Derived class 1 (inherits from Base) | ||
class Derived1 : public Base { | ||
public: | ||
Derived1() { | ||
cout << "Derived1 class constructor called." << endl; | ||
} | ||
~Derived1() { | ||
cout << "Derived1 class destructor called." << endl; | ||
} | ||
}; | ||
|
||
// Derived class 2 (inherits from Derived1) | ||
class Derived2 : public Derived1 { | ||
public: | ||
Derived2() { | ||
cout << "Derived2 class constructor called." << endl; | ||
} | ||
~Derived2() { | ||
cout << "Derived2 class destructor called." << endl; | ||
} | ||
}; | ||
|
||
int main() { | ||
// Creating object of Derived2 class | ||
Derived2 obj; | ||
|
||
// The constructors and destructors will be called in a specific order | ||
return 0; | ||
} |