Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
C++ Program for Multi-Level Inheritance (Grandparent → Parent → Child)
✅ C++ Program to Demonstrate Multi-Level Inheritance
#include <iostream>
using namespace std;
class grandparent {
public:
void display1() {
cout << "Hello I am your grandparent:\n";
}
};
class parent : public grandparent {
public:
void display2() {
cout << "Hello I am parent:\n";
}
};
class child : public parent {
public:
void display3() {
cout << "Hello I am child:\n";
}
};
int main() {
child obj;
obj.display1();
obj.display2();
obj.display3();
}
๐ Explanation:
This program demonstrates the concept of multi-level inheritance in C++.
- The grandparent class defines display1().
- The parent class inherits from grandparent and adds display2().
- The child class inherits from parent and adds display3().
- Thus, an object of the child class can access functions from all three classes.
๐งพ Sample Output:
Hello I am your grandparent: Hello I am parent: Hello I am child:
๐ Keywords:
C++ multi-level inheritance example, grandparent parent child program, inheritance in C++, OOP in C++, C++ object oriented programming
๐ Hashtags:
#CPlusPlus #Inheritance #MultiLevelInheritance #OOP #CppExamples #CodingForBeginners
๐ Search Description:
This C++ program demonstrates multi-level inheritance where a child class inherits from a parent, which in turn inherits from a grandparent class. Includes example code, explanation, and sample output.
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment