Skip to content

Commit

Permalink
Merge pull request #45 from rpandox/feat/mult-levl-inheritance-q3
Browse files Browse the repository at this point in the history
feat: Create q3 for multi level inheritance
  • Loading branch information
gaurovgiri authored Oct 22, 2024
2 parents 95d9700 + 49e381b commit dde6407
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions programs/Inheritance/Multilevel Inheritance/q3.cpp
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;
}

0 comments on commit dde6407

Please sign in to comment.