Written by Sai Sandeep Thota on April 5, 2013 in C++ > Programming

What is Hybrid Inheritance?

GET ALERTS:

Get our Latest updates delivered to your mailbox!

We have discussed about Single, Multilevel, Multiple and Hierarchical Inheritance. If you are don’t know about Inheritance, Read this article on What is Inheritance. Hybrid Inheritance can be defined as a mixture or presence of two or more Inheritance. Take a look at the picture below:

What is Hybrid Inheritance?

#include<conio.h>
#include<iostream.h>

class hybrid {
	protected:
	int x, y;
	public:
	void setvalues(int a, int b) {
		x=a;
		y=b;
	}
};

class hybrid1 {
	public:
	int abc;
};

class derived1 : public hybrid {
	protected:
	int z;
	public:
	void mul() {
		z=x*y;
		cout<<"\nZ Value (x*y) = "<<z;

	}
};

class derived2 : protected hybrid {
	protected:
	int k;
	public:
	void sety() {
	int a=10; int b=20;
	setvalues(a,b);
	}
	void sum() {
		k=x+y;
		cout<<"\nK Value is (x+y) = "<<k;
	}
};

class derived3 : public hybrid, public  hybrid1 {
	public:
	void geta(int xyz) {
	abc=xyz;
	cout<<"\nValue of ABC:"<<abc;
	}
};

void main() {
	derived1 ob;
	derived2 ob1;
	derived3 ob2;
	clrscr();
	ob.setvalues(10,20);
	ob.mul();
	ob1.sety();
	cout<<"\n";
	ob1.sum();
	ob2.geta(2);
	getch();
}

Output:
hybrid-inheritance

{ 1 comment… read it below or add one }

eswar teja April 14, 2013 at 5:51 pm

thankzzzzz

Reply

Leave a Comment

Previous post:

Next post: