-
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 #45 from rpandox/feat/mult-levl-inheritance-q3
feat: Create q3 for multi level inheritance
- Loading branch information
Showing
1 changed file
with
46 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,46 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
// Base class | ||
class Grandparent | ||
{ | ||
public: | ||
void displayGrandparent() | ||
{ | ||
cout << "This is the Grandparent class." << endl; | ||
} | ||
}; | ||
|
||
// Derived class from Grandparent | ||
class Parent : public Grandparent | ||
{ | ||
public: | ||
void displayParent() | ||
{ | ||
cout << "This is the Parent class." << endl; | ||
} | ||
}; | ||
|
||
// Derived class from Parent | ||
class Child : public Parent | ||
{ | ||
public: | ||
void displayChild() | ||
{ | ||
cout << "This is the Child class." << endl; | ||
} | ||
}; | ||
|
||
// Main function | ||
int main() | ||
{ | ||
// Creating an object of the Child class | ||
Child obj; | ||
|
||
// Accessing methods from all levels of inheritance | ||
obj.displayGrandparent(); // Method from Grandparent class | ||
obj.displayParent(); // Method from Parent class | ||
obj.displayChild(); // Method from Child class | ||
|
||
return 0; | ||
} |