SlideShare a Scribd company logo
4
Most read
7
Most read
16
Most read
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

PPTX
Abstract Class Presentation
tigerwarn
 
PPTX
Inheritance In C++ (Object Oriented Programming)
Gajendra Singh Thakur
 
PPT
Inheritance
poonam.rwalia
 
PPTX
Polymorphism Using C++
PRINCE KUMAR
 
PPTX
inheritance
Nivetha Elangovan
 
PPTX
Inline Functions and Default arguments
Nikhil Pandit
 
PPTX
virtual function
VENNILAV6
 
PPTX
Evaluation of postfix expression
Akhil Ahuja
 
Abstract Class Presentation
tigerwarn
 
Inheritance In C++ (Object Oriented Programming)
Gajendra Singh Thakur
 
Inheritance
poonam.rwalia
 
Polymorphism Using C++
PRINCE KUMAR
 
inheritance
Nivetha Elangovan
 
Inline Functions and Default arguments
Nikhil Pandit
 
virtual function
VENNILAV6
 
Evaluation of postfix expression
Akhil Ahuja
 

What's hot (20)

PDF
Constructors and destructors
Prof. Dr. K. Adisesha
 
PPTX
Inheritance in JAVA PPT
Pooja Jaiswal
 
PDF
itft-Decision making and branching in java
Atul Sehdev
 
PPTX
Package in Java
lalithambiga kamaraj
 
PPT
Exception Handling in JAVA
SURIT DATTA
 
PPS
Introduction to class in java
kamal kotecha
 
PPTX
Types of Constructor in C++
Bhavik Vashi
 
PPTX
Constructor overloading & method overloading
garishma bhatia
 
PPTX
Inheritance in java
Tech_MX
 
PPTX
Abstract class in c++
Sujan Mia
 
PPSX
Data Types & Variables in JAVA
Ankita Totala
 
PPTX
Constructor in java
Madishetty Prathibha
 
PPTX
Inheritance in Object Oriented Programming
Ashita Agrawal
 
PPTX
Inheritance and Polymorphism in java simple and clear
ASHNA nadhm
 
PPT
Method overriding
Azaz Maverick
 
PPTX
Applets in java
Wani Zahoor
 
PPTX
Inheritance in OOPS
Ronak Chhajed
 
PPTX
Pure virtual function and abstract class
Amit Trivedi
 
PPTX
Polymorphism in c++(ppt)
Sanjit Shaw
 
Constructors and destructors
Prof. Dr. K. Adisesha
 
Inheritance in JAVA PPT
Pooja Jaiswal
 
itft-Decision making and branching in java
Atul Sehdev
 
Package in Java
lalithambiga kamaraj
 
Exception Handling in JAVA
SURIT DATTA
 
Introduction to class in java
kamal kotecha
 
Types of Constructor in C++
Bhavik Vashi
 
Constructor overloading & method overloading
garishma bhatia
 
Inheritance in java
Tech_MX
 
Abstract class in c++
Sujan Mia
 
Data Types & Variables in JAVA
Ankita Totala
 
Constructor in java
Madishetty Prathibha
 
Inheritance in Object Oriented Programming
Ashita Agrawal
 
Inheritance and Polymorphism in java simple and clear
ASHNA nadhm
 
Method overriding
Azaz Maverick
 
Applets in java
Wani Zahoor
 
Inheritance in OOPS
Ronak Chhajed
 
Pure virtual function and abstract class
Amit Trivedi
 
Polymorphism in c++(ppt)
Sanjit Shaw
 
Ad

Similar to Multiple Inheritance (20)

PPTX
OOPS IN C++
Amritsinghmehra
 
PPTX
Inheritance
Burhan Ahmed
 
PDF
Chapter 6 and inheritance OOP C++ tu ioe
EZERR1
 
PDF
chapter-10-inheritance.pdf
study material
 
PDF
Constructor & destructor
Swarup Boro
 
DOCX
Unit3 java
mrecedu
 
PPTX
Inheritance and Interfaces
NAGASURESH MANOHARAN
 
PDF
Inheritance
Pranali Chaudhari
 
PPTX
Aryan's pres. entation.pptx
mohitsinha7739289047
 
ODP
Ppt of c++ vs c#
shubhra chauhan
 
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
PDF
lecture 6.pdf
WaqarRaj1
 
PPTX
Inheritance & interface ppt Inheritance
narikamalliy
 
PPTX
Inheritance
zindadili
 
PPT
Lecture 14 (inheritance basics)
Abhishek Khune
 
PPTX
Introduction to inheritance and different types of inheritance
huzaifaakram12
 
PDF
Inheritance and interface
Shubham Sharma
 
PDF
Inheritance
Prof. Dr. K. Adisesha
 
PDF
c++Inheritance.pdf
RanjanaThakuria1
 
PPT
MODULE2_INHERITANCE_SESSION1.ppt computer
ssuser6f3c8a
 
OOPS IN C++
Amritsinghmehra
 
Inheritance
Burhan Ahmed
 
Chapter 6 and inheritance OOP C++ tu ioe
EZERR1
 
chapter-10-inheritance.pdf
study material
 
Constructor & destructor
Swarup Boro
 
Unit3 java
mrecedu
 
Inheritance and Interfaces
NAGASURESH MANOHARAN
 
Inheritance
Pranali Chaudhari
 
Aryan's pres. entation.pptx
mohitsinha7739289047
 
Ppt of c++ vs c#
shubhra chauhan
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
 
lecture 6.pdf
WaqarRaj1
 
Inheritance & interface ppt Inheritance
narikamalliy
 
Inheritance
zindadili
 
Lecture 14 (inheritance basics)
Abhishek Khune
 
Introduction to inheritance and different types of inheritance
huzaifaakram12
 
Inheritance and interface
Shubham Sharma
 
c++Inheritance.pdf
RanjanaThakuria1
 
MODULE2_INHERITANCE_SESSION1.ppt computer
ssuser6f3c8a
 
Ad

Recently uploaded (20)

PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PPTX
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
PPTX
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PPTX
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PDF
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
PPTX
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
PPTX
quantum computing transition from classical mechanics.pptx
gvlbcy
 
PDF
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
PDF
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PPTX
Tunnel Ventilation System in Kanpur Metro
220105053
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
FUNDAMENTALS OF ELECTRIC VEHICLES UNIT-1
MikkiliSuresh
 
database slide on modern techniques for optimizing database queries.pptx
aky52024
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
Civil Engineering Practices_BY Sh.JP Mishra 23.09.pptx
bineetmishra1990
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Introduction to Ship Engine Room Systems.pdf
Mahmoud Moghtaderi
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
top-5-use-cases-for-splunk-security-analytics.pdf
yaghutialireza
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Machine Learning All topics Covers In This Single Slides
AmritTiwari19
 
22PCOAM21 Session 1 Data Management.pptx
Guru Nanak Technical Institutions
 
quantum computing transition from classical mechanics.pptx
gvlbcy
 
Cryptography and Information :Security Fundamentals
Dr. Madhuri Jawale
 
FLEX-LNG-Company-Presentation-Nov-2017.pdf
jbloggzs
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
Tunnel Ventilation System in Kanpur Metro
220105053
 

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 ⊚ [email protected]
  • 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