Multi level inheritence

RanaMOIN1 967 views 11 slides Feb 09, 2019
Slide 1
Slide 1 of 11
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11

About This Presentation

simple and easy with core concept


Slide Content

Multilevel Inheritence 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

Multilevel Inheritence 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.

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 ---------- };

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.

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

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

Example of Multilevel Inheritance in C++ main() { D1 x; x .assign (10, 2); x .sum (); x .product(); return 0; }

Output of Program Sum of 10 and 2 = 12 Product of 10 and 2 = 20

Diagrammatically

Natural inheritence
Tags