Skip to main content

Multiple Inheritance in C++

 

#include<bits/stdc++.h>
using namespace std;

class A{
    protected:
    int x;
    public:
    void set_data1(int m){
        x=m;
    }
};
class B{
    protected:
    int y;
    public:
    void set_data2(int n){
        y=n;
    }
};

class C: public A, public B{
    public:
   
    void display(){
   
        cout<<"The value of x: "<<x<<endl;
        cout<<"The value of y: "<<y<<endl;
        cout<<"The sum of x and y: "<<x + y<<endl;}
       
};
int main()
{
    C i;
    i.set_data1(4);
    i.set_data2(2);
    i.display();
    return 0;
}

Comments