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 Multiple Inheritance (Grandparent, Parent, Child)
✅ C++ Program to Demonstrate Multiple Inheritance
#include <iostream>
using namespace std;
class grandparent {
public:
void gp() {
cout << "Hi I am your grandparent:\n";
}
};
class parent {
public:
void p() {
cout << "Hi I am your parent:\n";
}
};
class child : public grandparent, public parent {
public:
void c() {
cout << "Hello I am your child:\n";
}
};
int main() {
child obj;
obj.gp();
obj.p();
obj.c();
}
๐ Explanation:
This program demonstrates the concept of multiple inheritance in C++.
- The grandparent class has a function gp().
- The parent class has a function p().
- The child class inherits from both grandparent and parent.
- The child object can call functions from both its parent and grandparent, along with its own function.
๐งพ Sample Output:
Hi I am your grandparent: Hi I am your parent: Hello I am your child:
๐ Keywords:
C++ multiple inheritance example, grandparent parent child program, inheritance in C++, OOP in C++, C++ object oriented programming
๐ Hashtags:
#CPlusPlus #Inheritance #MultipleInheritance #OOP #CppExamples #CodingForBeginners
๐ Search Description:
This C++ program demonstrates multiple inheritance where a child class inherits from both a grandparent and a parent 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