Multi-level Inheritance

Estudies4you

3. Multi-level Inheritance

It refers to the process of deriving a class from another derived class as shown in the figure below,
Multi level Inheritance definition,define Multi level Inheritance,Multi level Inheritance notes,Multi level Inheritance study material,Multi level Inheritance syntax,syntax for Multi level Inheritance,examples of Multi level Inheritance,programs for Multi level Inheritance,Multi level Inheritance examples,Multi level Inheritance programs,explain about Multi level Inheritance,discuss Multi level Inheritance details,discuss about Multi level Inheritance,estudies4you,c++ lecture notes,c++ study material jntu
Figure: Multi-level Inheritance
Syntax
class BaseClass
{
-----
};
class DerivedClass1 : Visibility BaseClass
{
-----
};
class DerivedClass2 : Visibility DerivedClass1
{
-----
};

Example
class Automobiles
{
// body
};
class Cars : public Automobiles
{
//body
};
class Mercedez : public Cars
{
//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 Increment:public Salary
{
private:
float inc;
public:
void show(void);
};
void Increment: :show(void)
{
if (sal > 10000.00)
{
sal = sal + 1000.00;
inc = sal;
cout<<“Salary after increment is:”<<inc<<endl;
}
else
{
cout<<“No increment”<<endl;
}
}
void main()
{
increment i, j;
clrscr();
i.set_id(100);
i.show_id();
i.setSal(15000,00);
i.showSal( );
i.show( );
j.set_id(101);
j.show_id();
j.setSal(9000.00);
j.showSal();
j.show( );
getch();
return;
}
Output
Multi level Inheritance definition,define Multi level Inheritance,Multi level Inheritance notes,Multi level Inheritance study material,Multi level Inheritance syntax,syntax for Multi level Inheritance,examples of Multi level Inheritance,programs for Multi level Inheritance,Multi level Inheritance examples,Multi level Inheritance programs,explain about Multi level Inheritance,discuss Multi level Inheritance details,discuss about Multi level Inheritance,estudies4you,c++ lecture notes,c++ study material jntu

To Top