SlideShare a Scribd company logo
1 of 21
1
Multiple Inheritance
Harsh wadhwani
19CS40
COMPUTER SCIENCE(C-2)
Bhavya Jain
19CS19
COMPUTER SCIENCE(C-
1)
.
• The capability of a class to derive
properties(the data members) and
functionality(the member functions)
from another class is
called Inheritance. Inheritance is one
of the most important key feature
of Object Oriented Programming.
What is parent class?
The class that is being inherited
inherited by other class is
class is known as parent class, super
class, super class or base class.
class.
What is child class?
A class that inherits another class is
class is known as child class, derived 3
Animal
Dog
In this type of inheritance a single
derived class may inherit from two or
more than two base classes. This means
that a single child class can have
multiple parent classes. Using comma
separation list
4
5
ILLUSTRATION
BIRD
A1 A2 A-n
Macaw
-
Species
SYNTAX :
Class subclass_name:
access_mode base_class1,
access_mode base_class2,
….;
{
//body of subclass
};
6
EXAMPLE:
#include <iostream>
using namespace std;
class bird {
public:
void type()
{
cout << " Aquatic flightless bird" << endl;
}
};
class adaptation {
public:
void life()
{
cout << "Adapted for life in the water" << endl;
}
};
class penguin: public bird, public adaptation{
};
int main()
{
penguin p1;
p1.type();
p1.life();
return 0;
}
7
Output :
CONSTRUCTORS CALLING :
• The constructors of Inherited classes
are called in the same order in which
they are inherited.
For example ,in the following programme
m mammal’s class constructor called before
c class winged animal’s constructor
8
EXAMPLE :
9
#include <iostream>
using namespace std;
class Mammal
{
public:
Mammal()
{
cout << "Mammals can give direct birth."
<< endl;
}
};
class WingedAnimal
{
public:
WingedAnimal()
{
cout << "Winged animal can flap." << endl;
}
};
class Bat: public Mammal, public
WingedAnimal {
};
int main()
{
Bat b1;
return 0;
}
Output :
PARAMETERISED AND DEFAULT CONSTRUCTORS :
#include <iostream>
using namespace std;
class A {
public:
A(){
cout<<" Default Constructor of A class"<<endl;}
A(int x){
cout<<" Parameterized Constructor of A class"<<endl;
}
};
class B {
public:
B(){
cout<<" Default Constructor of B class"<<endl;}
B(int g){
cout<<" Parameterized Constructor of B class"<<endl;
}
};
10
class C: public A, public B {
public:
C(){
cout<<" Default Constructor of C class"<<endl;
}
C(int z):A(z),B(z){
cout<<" Parameterzied Constructor of C class"<<endl;
}
};
int main() {
C obj(20);
return 0;
}
Output:
AMBIGUITY IN MULTIPLE INHERITANCE :
• What if same function is present in both the parent classes??
11
If we try to call the
function using the object
of the derived class,
compiler shows error.
It's because compiler
doesn't know which
function to call.
For example,
class base1
{ public:
void someFunction( ) { .... ... .... } };
class base2
{ public:
void someFunction( ) { .... ... .... } };
class derived : public base1, public base2 {
};
int main()
{ derived obj;
obj.someFunction() ; // Error!
return 0;
}
ONE POSSIBLE SOLUTION IS :
12
• The above issue can
be resolved by using
the Scope resolution
operator with the
function or we can say
explicitly calling
int main()
{
obj.base1::someFunction( );
// Function of base1 class is called
obj.base2::someFunction();
// Function of base2 class is called.
return0;
}
DIFFERENCE BETWEEN
MULTIPLE INHERITANCE AND MULTILEVEL INHERITANCE
13
Multiple Inheritance Multilevel Inheritance
“Multiple Inheritance” refers to the
concept of one class extending(or
inherits)
More than one base class
In this type of inheritance, a derived
class is created from another
derived class.
14
15
16
First Second Last
17
Link :
18
THANKS!
Any questions?
You can find me at:
⊚ @username
⊚ user@mail.me
SlidesCarnival icons are editable shapes.
This means that you can:
⊚ Resize them without losing quality.
⊚ Change fill color and opacity.
⊚ Change line color, width and style.
Isn’t that nice? :)
Examples:
19
Find more icons at slidescarnival.com/extra-
free-resources-icons-and-maps
20
DIAGRAMS AND INFOGRAPHICS
✋👆👉👍👤👦👧👨👩👪💃🏃💑❤😂😉
😋😒😭👶😸🐟🍒🍔💣📌📖🔨🎃🎈🎨🏈
🏰🌏🔌🔑 and many more...
😉
You can also use any emoji as an icon!
And of course it resizes without losing quality.
How? Follow Google instructions
https://twitter.com/googledocs/status/730087240156643328
21

More Related Content

What's hot

Java™ (OOP) - Chapter 8: "Objects and Classes"
Java™ (OOP) - Chapter 8: "Objects and Classes"Java™ (OOP) - Chapter 8: "Objects and Classes"
Java™ (OOP) - Chapter 8: "Objects and Classes"Gouda Mando
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in javaRahulAnanda1
 
Inheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingInheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingAshita Agrawal
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++Vishal Patil
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++Sujan Mia
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend classAbhishek Wadhwa
 
Friend functions
Friend functions Friend functions
Friend functions Megha Singh
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++Laxman Puri
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract classAmit Trivedi
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance pptNivegeetha
 

What's hot (20)

Java™ (OOP) - Chapter 8: "Objects and Classes"
Java™ (OOP) - Chapter 8: "Objects and Classes"Java™ (OOP) - Chapter 8: "Objects and Classes"
Java™ (OOP) - Chapter 8: "Objects and Classes"
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
 
Inheritance in Object Oriented Programming
Inheritance in Object Oriented ProgrammingInheritance in Object Oriented Programming
Inheritance in Object Oriented Programming
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Inheritance
InheritanceInheritance
Inheritance
 
Multiple inheritance in c++
Multiple inheritance in c++Multiple inheritance in c++
Multiple inheritance in c++
 
Friend function & friend class
Friend function & friend classFriend function & friend class
Friend function & friend class
 
Friend functions
Friend functions Friend functions
Friend functions
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
Method overriding
Method overridingMethod overriding
Method overriding
 
inheritance
inheritanceinheritance
inheritance
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Encapsulation C++
Encapsulation C++Encapsulation C++
Encapsulation C++
 
Inheritance In Java
Inheritance In JavaInheritance In Java
Inheritance In Java
 
Pure virtual function and abstract class
Pure virtual function and abstract classPure virtual function and abstract class
Pure virtual function and abstract class
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance ppt
Inheritance pptInheritance ppt
Inheritance ppt
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
C# Inheritance
C# InheritanceC# Inheritance
C# Inheritance
 

Similar to Multiple Inheritance

Similar to Multiple Inheritance (20)

OOPS IN C++
OOPS IN C++OOPS IN C++
OOPS IN C++
 
Inheritance
InheritanceInheritance
Inheritance
 
chapter-10-inheritance.pdf
chapter-10-inheritance.pdfchapter-10-inheritance.pdf
chapter-10-inheritance.pdf
 
Constructor & destructor
Constructor & destructorConstructor & destructor
Constructor & destructor
 
Unit3 java
Unit3 javaUnit3 java
Unit3 java
 
Inheritance and Interfaces
Inheritance and InterfacesInheritance and Interfaces
Inheritance and Interfaces
 
Inheritance
InheritanceInheritance
Inheritance
 
Ppt of c++ vs c#
Ppt of c++ vs c#Ppt of c++ vs c#
Ppt of c++ vs c#
 
lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
Inheritance
InheritanceInheritance
Inheritance
 
Lecture 14 (inheritance basics)
Lecture 14 (inheritance basics)Lecture 14 (inheritance basics)
Lecture 14 (inheritance basics)
 
Inheritance and interface
Inheritance and interfaceInheritance and interface
Inheritance and interface
 
Inheritance
InheritanceInheritance
Inheritance
 
c++Inheritance.pdf
c++Inheritance.pdfc++Inheritance.pdf
c++Inheritance.pdf
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computer
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
Inheritance Inheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
inheritance
inheritanceinheritance
inheritance
 
inheritance in OOPM
inheritance in OOPMinheritance in OOPM
inheritance in OOPM
 

Recently uploaded

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 

Recently uploaded (20)

main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 

Multiple Inheritance

  • 1. 1 Multiple Inheritance Harsh wadhwani 19CS40 COMPUTER SCIENCE(C-2) Bhavya Jain 19CS19 COMPUTER SCIENCE(C- 1) .
  • 2. • The capability of a class to derive properties(the data members) and functionality(the member functions) from another class is called Inheritance. Inheritance is one of the most important key feature of Object Oriented Programming.
  • 3. What is parent class? The class that is being inherited inherited by other class is class is known as parent class, super class, super class or base class. class. What is child class? A class that inherits another class is class is known as child class, derived 3 Animal Dog
  • 4. In this type of inheritance a single derived class may inherit from two or more than two base classes. This means that a single child class can have multiple parent classes. Using comma separation list 4
  • 6. SYNTAX : Class subclass_name: access_mode base_class1, access_mode base_class2, ….; { //body of subclass }; 6
  • 7. EXAMPLE: #include <iostream> using namespace std; class bird { public: void type() { cout << " Aquatic flightless bird" << endl; } }; class adaptation { public: void life() { cout << "Adapted for life in the water" << endl; } }; class penguin: public bird, public adaptation{ }; int main() { penguin p1; p1.type(); p1.life(); return 0; } 7 Output :
  • 8. CONSTRUCTORS CALLING : • The constructors of Inherited classes are called in the same order in which they are inherited. For example ,in the following programme m mammal’s class constructor called before c class winged animal’s constructor 8
  • 9. EXAMPLE : 9 #include <iostream> using namespace std; class Mammal { public: Mammal() { cout << "Mammals can give direct birth." << endl; } }; class WingedAnimal { public: WingedAnimal() { cout << "Winged animal can flap." << endl; } }; class Bat: public Mammal, public WingedAnimal { }; int main() { Bat b1; return 0; } Output :
  • 10. PARAMETERISED AND DEFAULT CONSTRUCTORS : #include <iostream> using namespace std; class A { public: A(){ cout<<" Default Constructor of A class"<<endl;} A(int x){ cout<<" Parameterized Constructor of A class"<<endl; } }; class B { public: B(){ cout<<" Default Constructor of B class"<<endl;} B(int g){ cout<<" Parameterized Constructor of B class"<<endl; } }; 10 class C: public A, public B { public: C(){ cout<<" Default Constructor of C class"<<endl; } C(int z):A(z),B(z){ cout<<" Parameterzied Constructor of C class"<<endl; } }; int main() { C obj(20); return 0; } Output:
  • 11. AMBIGUITY IN MULTIPLE INHERITANCE : • What if same function is present in both the parent classes?? 11 If we try to call the function using the object of the derived class, compiler shows error. It's because compiler doesn't know which function to call. For example, class base1 { public: void someFunction( ) { .... ... .... } }; class base2 { public: void someFunction( ) { .... ... .... } }; class derived : public base1, public base2 { }; int main() { derived obj; obj.someFunction() ; // Error! return 0; }
  • 12. ONE POSSIBLE SOLUTION IS : 12 • The above issue can be resolved by using the Scope resolution operator with the function or we can say explicitly calling int main() { obj.base1::someFunction( ); // Function of base1 class is called obj.base2::someFunction(); // Function of base2 class is called. return0; }
  • 13. DIFFERENCE BETWEEN MULTIPLE INHERITANCE AND MULTILEVEL INHERITANCE 13 Multiple Inheritance Multilevel Inheritance “Multiple Inheritance” refers to the concept of one class extending(or inherits) More than one base class In this type of inheritance, a derived class is created from another derived class.
  • 14. 14
  • 15. 15
  • 18. 18 THANKS! Any questions? You can find me at: ⊚ @username ⊚ user@mail.me
  • 19. SlidesCarnival icons are editable shapes. This means that you can: ⊚ Resize them without losing quality. ⊚ Change fill color and opacity. ⊚ Change line color, width and style. Isn’t that nice? :) Examples: 19 Find more icons at slidescarnival.com/extra- free-resources-icons-and-maps
  • 21. ✋👆👉👍👤👦👧👨👩👪💃🏃💑❤😂😉 😋😒😭👶😸🐟🍒🍔💣📌📖🔨🎃🎈🎨🏈 🏰🌏🔌🔑 and many more... 😉 You can also use any emoji as an icon! And of course it resizes without losing quality. How? Follow Google instructions https://twitter.com/googledocs/status/730087240156643328 21