Skip to content

Commit

Permalink
Merge pull request #48 from rpandox/feat/mult-levl-iinheritance-q4
Browse files Browse the repository at this point in the history
Feat/mult-levl-iinheritance-q4
  • Loading branch information
gaurovgiri authored Oct 22, 2024
2 parents dde6407 + df109e5 commit 57270e2
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions programs/Inheritance/Multilevel Inheritance/q4.cpp
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;
}

0 comments on commit 57270e2

Please sign in to comment.