Skip to content

Instantly share code, notes, and snippets.

@dhpradeep
Last active August 27, 2021 10:20
Show Gist options
  • Save dhpradeep/d25aeb42cec47a699380c5b6fc9eb294 to your computer and use it in GitHub Desktop.
Save dhpradeep/d25aeb42cec47a699380c5b6fc9eb294 to your computer and use it in GitHub Desktop.
Suppose you as a derived class and you mom and dad as a parent class. Relating to this, write a program and explain the concepts of multiple inheritance.

Suppose you as a derived class and you mom and dad as a parent class. Relating to this, write a program and explain the concepts of inheritance, encapsulation and polymorphism of Object oriented programming.

Multiple Inheritance

image2

This relationship explain the multiple inheritance, where one class is derived from two or multiple parent class

Multiple inheritance is the type of inheritance in which a derived class inherits multiple base classes. In multiple inheritance, the derived class combines the members of all the base classes

Here is the syntax:

class Child_class : visibility parent_class1, visibility parent_class2,….
{  
    // Body of the class;  
}

Here is the sample example of multiple inheritance:

#include <iostream>  
using namespace std;  
class A  {  
  private:  
     int a;  
  public:  
    void In() {  
      cout<<”Enter a:”;
      cin>>a;
    }  
    void Out()  {
       cout<<”a=”<<a<<endl;
    }
};  
  
class B  {  
  private:  
    int b;  
    public:  
      void Input(){  
        cout<<”Enter b:”;
      cin>>b;
      }  
      void Output(){
       cout<<”b=”<<b<<endl;
      }
}; 

class C : public A,public B {  
  private c:  
  int c;  
  public:  
    void get(){  
        A::In();
        B::Input();
        cout<<”Enter c:”;
        cin>>c;
    }  
     void Show(){
        A::Out();
        B::Output();
        cout<<”c=”<<c<<endl;
     }
    int main(){  
      C c;  
      c.get();  
    c.show();  
    getch();  
    return 0;  
  }  
};

Ambiguity occurs in the multiple inheritance when a function with the same name occurs in more than one parent class. One of the most serious issues in multiple inheritance is the issue of ambiguity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment