Sunday, September 25, 2016

Hybrid Inheritance

Hybrid Inheritance is that type in which we combine two or more types of inheritance.

Program To Illustrate the Concept of Hybrid Inheritance:

#include<iostream>
using namespace std;
class Student
{
int rollno;
public:
void getnum(int a)
{
rollno=a;
}
void putnum()
{
cout<<"Roll Number is "<<rollno;
}
};
class Marks:public Student
{ protected:
float sub1,sub2;
public:
void getmarks(float a,float b)
{
sub1=a;
sub2=b;
}
void display()
{
cout<<"\nSubject 1="<<sub1;
cout<<"\nSubject 2="<<sub2;
}

};
class sports
{protected:
int sport;
public:
void getsport(int a)
{
sport=a;
}
void displaysport()
{
cout<<"\nMarks In Sports="<<sport;
}
};
class result:public sports,public Marks
{
float total;
public:
void output()
{total=sub1+sub2+sport;
cout<<"\nTotal Marks="<<total;
}
};
main()
{
result r;
r.getnum(712299);
r.getmarks(98.5,89.6);
r.getsport(89);
r.putnum();
r.display();
r.displaysport();
r.output();
}

Also See Hierarchical Inheritance