-
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 #44 from rpandox/feat/mult-levl-inheritance-q2
feat: add question 2 to multilevel inheritance
- Loading branch information
Showing
2 changed files
with
48 additions
and
2 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,46 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
// Base class | ||
class Base | ||
{ | ||
public: | ||
void displayBase() | ||
{ | ||
cout << "This is the Base class." << endl; | ||
} | ||
}; | ||
|
||
// Intermediate class derived from Base | ||
class Intermediate : public Base | ||
{ | ||
public: | ||
void displayIntermediate() | ||
{ | ||
cout << "This is the Intermediate class." << endl; | ||
} | ||
}; | ||
|
||
// Derived class derived from Intermediate | ||
class Derived : public Intermediate | ||
{ | ||
public: | ||
void displayDerived() | ||
{ | ||
cout << "This is the Derived class." << endl; | ||
} | ||
}; | ||
|
||
// Main function | ||
int main() | ||
{ | ||
// Creating an object of the Derived class | ||
Derived obj; | ||
|
||
// Accessing methods from all levels of inheritance | ||
obj.displayBase(); // Method from Base class | ||
obj.displayIntermediate(); // Method from Intermediate class | ||
obj.displayDerived(); // Method from Derived class | ||
|
||
return 0; | ||
} |
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