Hybrid Inheritance

Estudies4you
5. Hybrid Inheritance
It is the combination of multi-level and multiple inheritance. Some program designing requires the involvement of two or more inheritance types, in such cases hybrid inheritance is used.
explain Hybrid Inheritance,define Hybrid Inheritance,Hybrid Inheritance definition,syntax for Hybrid Inheritance,Hybrid Inheritance syntax,examples for Hybrid Inheritance,Hybrid Inheritance examples,Hybrid Inheritance notes,Hybrid Inheritance study material,estudies4you,c++ lecture notes,c++ study material jntuh,oops using c++ lecture notes jntuh,
Figure: Hybrid Inheritance
Syntax
class A
{
--------
};
class B
{
--------
};
class C: visibility A, visibility B
{
--------
};
class D: visibility A
{
--------
};
Example
class Automobiles
{
//body
};
class cars : public Automobiles
{
//body
};
class Bicycle
{
//body
};
class Speed : public Cars, public Bicycle
{
//body
};

Program
#include<iostream.h>
#include<conio.h>
class Employee
{
protected:
int id;
public:
void set_id(int);
void show_id(void);
};
void Employee :: set_id(int x)
{
id =x;
}
void Employee :: show_id(void)
{
cout <<“Employee-id is:”<<id<<endl;
}
class Salary : public Employee
{
protected:
float sal;
public:
void setSal(float);
void showSal(void);
};
void Salary :: setSal(float S)
{
sal = S;
}
void Salary :: showSal(void)
{
cout <<“Employee salary is:”<<sal<<endl;
}
class yoservice
{
protected:
float yos;
public:
void setYrs(float y)
{
yos=y;
}
void showYrs(void)
{
cout <<“Years of service:”<<yos<<endl;
}
};
class increment : public Salary, public yoservice
{
private:
float inc;
public:
void show(void);
};
void increment :: show(void)
{
cout <<“Employee salary and years of service are:” <<sal<<“”<<yos<<endl;
if (sal > 10000.00 && yos > 3.0)
{
sal = sal + 1000.00;
inc = sal;
cout <<“Salary with increment is:”<<inc<<endl;
}
else
{
cout <<“No increment in salary”<<endl;
}
}
void main( )
{
increment i, j;
clrscr();
iset_id(100);
i.show_id();
i.setSal(15000.00);
i.showSal();
i.setYrs(2.2);
i.showYrs( );
i.show();
j.set_id(101);
j.show_id();
j.setSal(25000.00);
j.showSal();
j.setYrs(5.0);
j.showYrs();
j.show();
getch();
return;
}
Output
explain Hybrid Inheritance,define Hybrid Inheritance,Hybrid Inheritance definition,syntax for Hybrid Inheritance,Hybrid Inheritance syntax,examples for Hybrid Inheritance,Hybrid Inheritance examples,Hybrid Inheritance notes,Hybrid Inheritance study material,estudies4you,c++ lecture notes,c++ study material jntuh,oops using c++ lecture notes jntuh,

To Top