SlideShare a Scribd company logo
2
Most read
5
Most read
11
Most read
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
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
Multi level inheritence

More Related Content

PPTX
Polymorphism In c++
PDF
Operator overloading
PPTX
Templates in C++
PPTX
Multiple inheritance in c++
PPT
Polymorphism in java
PPTX
07. Virtual Functions
PPT
Operator Overloading
PDF
Exception handling
Polymorphism In c++
Operator overloading
Templates in C++
Multiple inheritance in c++
Polymorphism in java
07. Virtual Functions
Operator Overloading
Exception handling

What's hot (20)

PPTX
Single inheritance
PPTX
Inheritance
PPTX
Inheritance
PDF
Inheritance In Java
PPTX
classes and objects in C++
PPTX
Friend function
PPTX
Constructor in java
PPTX
Inheritance in oops
PPTX
Types of Constructor in C++
PPTX
Method overloading
PDF
Constructor and Destructor
PPTX
Inheritance in c++
PPTX
Java Inheritance
PPTX
Inheritance in java
PPTX
Abstract class in c++
PPTX
Inheritance in OOPS
PPTX
Inheritance in c++
PPTX
Inheritance in c++
PPTX
Java Inheritance - sub class constructors - Method overriding
PPTX
Inheritance in Object Oriented Programming
Single inheritance
Inheritance
Inheritance
Inheritance In Java
classes and objects in C++
Friend function
Constructor in java
Inheritance in oops
Types of Constructor in C++
Method overloading
Constructor and Destructor
Inheritance in c++
Java Inheritance
Inheritance in java
Abstract class in c++
Inheritance in OOPS
Inheritance in c++
Inheritance in c++
Java Inheritance - sub class constructors - Method overriding
Inheritance in Object Oriented Programming
Ad

Similar to Multi level inheritence (20)

PPT
E -COMMERCE.ppt
PPTX
Inheritance
PPTX
Inheritance
DOCX
oop database doc for studevsgdy fdsyn hdf
PPT
Module 4 Effect of Reuse on using Inheritance.ppt
PPTX
Inheritance (with classifications)
PPTX
iheritence.pptx
PPTX
Ritik (inheritance.cpp)
PPTX
Week 8 - OOP Inheritance11111111111.pptx
PPTX
Inheritance
PPTX
Programming Lesson by Slidesgo.pptx
PPT
week14 (1).ppt
PPTX
Inheritance
PPTX
types of inheritancec , inheritance ,data structures and algorithim oresentat...
PDF
lecture 6.pdf
PPTX
Inheritance.pptx
PPTX
Inheritance in c++theory
PPT
Inheritance.ppt
PPTX
inheritance
PDF
OOP Assign No.03(AP).pdf
E -COMMERCE.ppt
Inheritance
Inheritance
oop database doc for studevsgdy fdsyn hdf
Module 4 Effect of Reuse on using Inheritance.ppt
Inheritance (with classifications)
iheritence.pptx
Ritik (inheritance.cpp)
Week 8 - OOP Inheritance11111111111.pptx
Inheritance
Programming Lesson by Slidesgo.pptx
week14 (1).ppt
Inheritance
types of inheritancec , inheritance ,data structures and algorithim oresentat...
lecture 6.pdf
Inheritance.pptx
Inheritance in c++theory
Inheritance.ppt
inheritance
OOP Assign No.03(AP).pdf
Ad

Recently uploaded (20)

PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
composite construction of structures.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
web development for engineering and engineering
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
additive manufacturing of ss316l using mig welding
PDF
Digital Logic Computer Design lecture notes
PPTX
Geodesy 1.pptx...............................................
PDF
Structs to JSON How Go Powers REST APIs.pdf
DOCX
573137875-Attendance-Management-System-original
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PPTX
Welding lecture in detail for understanding
CYBER-CRIMES AND SECURITY A guide to understanding
composite construction of structures.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Foundation to blockchain - A guide to Blockchain Tech
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
web development for engineering and engineering
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
additive manufacturing of ss316l using mig welding
Digital Logic Computer Design lecture notes
Geodesy 1.pptx...............................................
Structs to JSON How Go Powers REST APIs.pdf
573137875-Attendance-Management-System-original
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Internet of Things (IOT) - A guide to understanding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Welding lecture in detail for understanding

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; }
  • 8. Output of Program • Sum of 10 and 2 = 12 • Product of 10 and 2 = 20