Multiple Inheritance in C++

In "Multiple Inheritance" their are two Parent class and one Child class.

LOGO


Basically in "Multiple Inheritance" their is more than one Parent class(BASE CLASS) which all are inherited to a single Child class(DERIVED CLASS).

Block-Diagram
BLOCK DIAGRAM


Syntax:-
class Parent1
{
//Body of the Parent-01 class
};
class Parent2
{
//Body of the Parent-02 class
};
class Child : access_specifier Parent1, access_specifier Parent2
{
//Body of the Child class
};

Example of Multiple Inheritance
#include<iostream>
using namespace std;

class Parent1
{
 protected:
  int a=10;
};
class Parent2
{
 protected: 
  int b=8;
};

//Inheriting two different classes in one class using ','
class Child : public Parent1, public Parent2
{
 public:
  int c=12;
  void put()
  {
   cout<<"Sum is "<<a+b+c;
  }
};
int main()
{
 Child x; //'x' is the object of "Child class"
 x.put();
}


Also visit ----

Introduction to Inheritance

Single Inheritance


For giving some suggestion please comment us or check our "Contact us" page. Also more update related to coding will be added in this Blog later on, so please get attached with this Blog by clicking the follow button. Thank you for your support and time...

Post a Comment

0 Comments