VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
Multi level inheritence
1. When a class is derived from a class which is also
derived from another class, i.e. a class having more
than one parent classes, such inheritance is called
Multilevel Inheritance
2. Child class
The class which inherits
the properties of another class is
called Derived or Child or Sub
class
Parent class
The class whose properties
are inherited is called Base or
Parent or Super class.
3. Syntax of Multilevel Inheritance
class A //Base class
{ ---------
--------- //body of class A
---------
};
class B : public A //B derived from class A
{ ----------
--------- //body of class B
----------
};
4. Syntax of Multilevel Inheritance
class C : public B //C derived from class B
{ ----------
--------- //body of class C
----------
};
//This process can be extended to any number of levels.
5. Example of Multilevel Inheritance in C++
#include<iostream>
using namespace std;
class B1
{
protected:
float m, n;
public:
assign (float x, float y)
{
m = x;
n = y;
}
}; //end base class B1
6. Example of Multilevel Inheritance in C++
class B2 : public B1
{
public:
sum()
{
cout<<"Sum of "<<m<<"and"<<n<<"="<<m+n<<endl;
}
}; //end derived class B2
class D1 : public B2
{
public:
product()
{
cout<<"Product of "<<m<<"and"<<n<<"="<<m*n<<endl;
}
}; //end derived class D1
7. Example of Multilevel Inheritance in C++
main()
{
D1 x;
x .assign (10, 2);
x .sum ();
x .product();
return 0;
}