Skip to content

Commit

Permalink
feat: Create q3 for multi level inheritance
Browse files Browse the repository at this point in the history
  • Loading branch information
rpandox committed Oct 21, 2024
1 parent f447d1f commit 49e381b
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 49e381b

Please sign in to comment.