Multiple Inheritance is a feature of C++ where a class can inherit from more than one classes. i.e one sub class is inherited from more than one base classes.
Syntax:
class Base_class_name : access_mode derived1_class, access_mode derived2 _class
{
//body of Base_class
}
Example:
#include<iostream>
using namespace std;
class Parent{ // Base class
public:
Parent(){
cout<< " This is Parent class " <<endl;
}
};
class Child1{ //derived1 class --> Base class
public:
Child1(){
cout<< " This is Child1 class " <<endl;
}
};
class Child2:public Parent ,public Child1{ //derived2 class --> Base class
public:
Child2(){
cout<< " This is Child2 class " <<endl;
}
};
int main(){
Child2 obj2;
}
Output:
This is Parent class
This is Child1 class
This is Child2 class
0 Comments
Thanks for Supporting me