SlideShare a Scribd company logo
1 of 46
Download to read offline
Inheritance in OOP/C++
prepared by:
WAQAR ISMAIL
One of the most important concepts in object-oriented
programming is that of inheritance. Inheritance allows us
to define a class in terms of another class, which makes it
easier to create and maintain an application. This also
provides an opportunity to reuse the code functionality
and fast implementation time.
When creating a class, instead of writing completely new
data members and member functions, the programmer
can designate that the new class should inherit the
members of an existing class.
C++ Inheritance
Inheritance is the process by which new classes called
derived classes are created from existing classes called
base classes.
The derived classes have all the features of the base
class and the programmer can choose to add new
features specific to the newly created derived class.
C++ Inheritance
“the mechanism by which one class acquires
the properties of another class”
C++ and inheritance
•The language mechanism by which one
class acquires the properties (data and
operations) of another class
•Base Class (or superclass): the class
being inherited from
•Derived Class (or subclass): the class
that inherits
Advantages of inheritance
•When a class inherits from another
class, there are three benefits:
•(1) You can reuse the methods and
data of the existing class
(2) You can extend the existing class by
adding new data and new methods
(3) You can modify the existing class by
overloading its methods with your own
implementations
Inheritance and accessibility
•A class inherits the behavior of another
class and enhances it in some way
•Inheritance does not mean inheriting
access to another class’ private
members
#include <iostream>
class BaseClass {
public:
BaseClass( ) : baseValue (20) { };
BaseClass(int aValue) : baseValue (aValue) { };
int baseValue;
};
class DerivedClass : public BaseClass {
public:
DerivedClass() : derivedValue (10){ };
DerivedClass(int aDerivedValue) : BaseClass(15),
derivedValue(aDerivedValue){ };
int getDerivedValue() { return derivedValue; }
private:
int derivedValue;
};
int main( )
{
BaseClass base;
DerivedClass child(5);
cout << base.baseValue << endl; // will print
20
cout << child.baseValue << endl; // will print
15
cout << child.getDerivedValue() << endl; //
will print 5
return 0;
}
Features or Advantages of Inheritance:
Reusability:
Inheritance helps the code to be reused in many
situations.
The base class is defined and once it is compiled, it
need not be reworked.
Using the concept of inheritance, the programmer can
create as many derived classes from the base class as
needed while adding specific features to each derived
class as needed.
C++ Inheritance
Features or Advantages of Inheritance:
Saves Time and Effort:
The above concept of reusability achieved by inheritance
saves the programmer time and effort. The main code
written can be reused in various situations as needed.
Increases Program Structure which results in
greater reliability.
C++ Inheritance
Reminder about public, private and protected access
specifiers:
1 If a member or variables defined in a class is private, then
they are accessible by members of the same class only and
cannot be accessed from outside the class.
2 Public members and variables are accessible from outside
the class.
3 Protected access specifier is a stage between private and
public. If a member functions or variables defined in a class
are protected, then they cannot be accessed from outside
the class but can be accessed from the derived class.
C++ Inheritance
When deriving a class from a base class, the base
class may be inherited through public, protected or
private inheritance. The type of inheritance is
specified by the access- specifier.
We hardly use protected or private inheritance,
but public inheritance is commonly used. While
using different type of inheritance, following rules are
applied:
Type of Inheritance
Public Inheritance: When deriving a class from
a public base class, public members of the base
class become public members of the derived class
and protected members of the base class
become protected members of the derived class. A
base class's private members are never accessible
directly from a derived class, but can be accessed
through calls to the public and protected members
of the base class.
Type of Inheritance
Protected Inheritance: When deriving from
a protected base class, public and protected
members of the base class
become protected members of the derived class.
Private Inheritance: When deriving from
a private base
class, public and protected members of the base
class become private members of the derived class
Type of Inheritance
1. Single class Inheritance:
Single inheritance is the one where you have a
single base class and a single derived class.
Types of Inheritance
Class Employee
Class Manager
It is a Base class (super)
it is a sub class (derived)
2. Multilevel Inheritance:
In Multi level inheritance, a class inherits its
properties from another derived class.
Types of Inheritance
Class A
Class B
it is a Base class (super) of B
it is a sub class (derived) of A
and base class of class C
Class C derived class(sub) of class B
3. Multiple Inheritances:
In Multiple inheritances, a derived class inherits
from multiple base classes. It has properties of
both the base classes.
Types of Inheritance
Class A Class B Base class
Class C Derived class
4. Hierarchical Inheritance:
In hierarchical Inheritance, it's like an inverted tree.
So multiple classes inherit from a single base
class. It's quite analogous to the File system in a
unix based system.
Types of Inheritance
Class A
Class B Class C
Class D
5. Hybrid Inheritance:
In this type of inheritance, we can have mixture of
number of inheritances but this can generate an
error of using same name function from no of
classes, which will bother the compiler to how to
use the functions.
Therefore, it will generate errors in the program.
This has known as ambiguity or duplicity.
Ambiguity problem can be solved by using virtual
base classes
Types of Inheritance
Types of Inheritance
Class A
Class B
Class D
Class C
5. Hybrid Inheritance:
Any Questions Please
Thank You
Very Much

More Related Content

Similar to lecture 6.pdf

Similar to lecture 6.pdf (20)

Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
Inheritance
InheritanceInheritance
Inheritance
 
6 Inheritance
6 Inheritance6 Inheritance
6 Inheritance
 
session 24_Inheritance.ppt
session 24_Inheritance.pptsession 24_Inheritance.ppt
session 24_Inheritance.ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
inheritance
inheritanceinheritance
inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
Inheritance
InheritanceInheritance
Inheritance
 
week14 (1).ppt
week14 (1).pptweek14 (1).ppt
week14 (1).ppt
 
Chapter25 inheritance-i
Chapter25 inheritance-iChapter25 inheritance-i
Chapter25 inheritance-i
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
 
Inheritance, Object Oriented Programming
Inheritance, Object Oriented ProgrammingInheritance, Object Oriented Programming
Inheritance, Object Oriented Programming
 
Inheritance
InheritanceInheritance
Inheritance
 
Single inheritance
Single inheritanceSingle inheritance
Single inheritance
 
Inheritance in c++ part1
Inheritance in c++ part1Inheritance in c++ part1
Inheritance in c++ part1
 
C++ Inheritance.pptx
C++ Inheritance.pptxC++ Inheritance.pptx
C++ Inheritance.pptx
 
Inheritance
InheritanceInheritance
Inheritance
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
 

Recently uploaded

call girls in G.T.B. Nagar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in  G.T.B. Nagar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in  G.T.B. Nagar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in G.T.B. Nagar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhiHauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhiHot Call Girls In Sector 58 (Noida)
 
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样gfghbihg
 
2024 TOP 10 most fuel-efficient vehicles according to the US agency
2024 TOP 10 most fuel-efficient vehicles according to the US agency2024 TOP 10 most fuel-efficient vehicles according to the US agency
2024 TOP 10 most fuel-efficient vehicles according to the US agencyHyundai Motor Group
 
UNIT-V-ELECTRIC AND HYBRID VEHICLES.pptx
UNIT-V-ELECTRIC AND HYBRID VEHICLES.pptxUNIT-V-ELECTRIC AND HYBRID VEHICLES.pptx
UNIT-V-ELECTRIC AND HYBRID VEHICLES.pptxDineshKumar4165
 
꧁༒☬ 7042364481 (Call Girl) In Dwarka Delhi Escort Service In Delhi Ncr☬༒꧂
꧁༒☬ 7042364481 (Call Girl) In Dwarka Delhi Escort Service In Delhi Ncr☬༒꧂꧁༒☬ 7042364481 (Call Girl) In Dwarka Delhi Escort Service In Delhi Ncr☬༒꧂
꧁༒☬ 7042364481 (Call Girl) In Dwarka Delhi Escort Service In Delhi Ncr☬༒꧂Hot Call Girls In Sector 58 (Noida)
 
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGERUNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGERDineshKumar4165
 
如何办理迈阿密大学毕业证(UM毕业证)成绩单留信学历认证原版一比一
如何办理迈阿密大学毕业证(UM毕业证)成绩单留信学历认证原版一比一如何办理迈阿密大学毕业证(UM毕业证)成绩单留信学历认证原版一比一
如何办理迈阿密大学毕业证(UM毕业证)成绩单留信学历认证原版一比一ga6c6bdl
 
办理学位证(MLU文凭证书)哈勒 维滕贝格大学毕业证成绩单原版一模一样
办理学位证(MLU文凭证书)哈勒 维滕贝格大学毕业证成绩单原版一模一样办理学位证(MLU文凭证书)哈勒 维滕贝格大学毕业证成绩单原版一模一样
办理学位证(MLU文凭证书)哈勒 维滕贝格大学毕业证成绩单原版一模一样umasea
 
Innovating Manufacturing with CNC Technology
Innovating Manufacturing with CNC TechnologyInnovating Manufacturing with CNC Technology
Innovating Manufacturing with CNC Technologyquickpartslimitlessm
 
VIP Kolkata Call Girl Kasba 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kasba 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kasba 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kasba 👉 8250192130 Available With Roomdivyansh0kumar0
 
Call Girls in Karachi | +923081633338 | Karachi Call Girls
Call Girls in Karachi  | +923081633338 | Karachi Call GirlsCall Girls in Karachi  | +923081633338 | Karachi Call Girls
Call Girls in Karachi | +923081633338 | Karachi Call GirlsAyesha Khan
 
Not Sure About VW EGR Valve Health Look For These Symptoms
Not Sure About VW EGR Valve Health Look For These SymptomsNot Sure About VW EGR Valve Health Look For These Symptoms
Not Sure About VW EGR Valve Health Look For These SymptomsFifth Gear Automotive
 
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一fjjwgk
 
( Best ) Genuine Call Girls In Mandi House =DELHI-| 8377087607
( Best ) Genuine Call Girls In Mandi House =DELHI-| 8377087607( Best ) Genuine Call Girls In Mandi House =DELHI-| 8377087607
( Best ) Genuine Call Girls In Mandi House =DELHI-| 8377087607dollysharma2066
 
Russian Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
Russian  Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...Russian  Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
Russian Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...shivangimorya083
 
Beautiful Vip Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
Beautiful Vip  Call Girls Punjabi Bagh 9711199012 Call /WhatsappsBeautiful Vip  Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
Beautiful Vip Call Girls Punjabi Bagh 9711199012 Call /Whatsappssapnasaifi408
 
UNOSAFE ELEVATOR PRIVATE LTD BANGALORE BROUCHER
UNOSAFE ELEVATOR PRIVATE LTD BANGALORE BROUCHERUNOSAFE ELEVATOR PRIVATE LTD BANGALORE BROUCHER
UNOSAFE ELEVATOR PRIVATE LTD BANGALORE BROUCHERunosafeads
 

Recently uploaded (20)

call girls in G.T.B. Nagar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in  G.T.B. Nagar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in  G.T.B. Nagar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in G.T.B. Nagar (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
sauth delhi call girls in Connaught Place🔝 9953056974 🔝 escort Service
sauth delhi call girls in  Connaught Place🔝 9953056974 🔝 escort Servicesauth delhi call girls in  Connaught Place🔝 9953056974 🔝 escort Service
sauth delhi call girls in Connaught Place🔝 9953056974 🔝 escort Service
 
Hot Sexy call girls in Pira Garhi🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Pira Garhi🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Pira Garhi🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Pira Garhi🔝 9953056974 🔝 escort Service
 
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhiHauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
Hauz Khas Call Girls ☎ 7042364481 independent Escorts Service in delhi
 
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
(办理学位证)(Rice毕业证)莱斯大学毕业证成绩单修改留信学历认证原版一模一样
 
2024 TOP 10 most fuel-efficient vehicles according to the US agency
2024 TOP 10 most fuel-efficient vehicles according to the US agency2024 TOP 10 most fuel-efficient vehicles according to the US agency
2024 TOP 10 most fuel-efficient vehicles according to the US agency
 
UNIT-V-ELECTRIC AND HYBRID VEHICLES.pptx
UNIT-V-ELECTRIC AND HYBRID VEHICLES.pptxUNIT-V-ELECTRIC AND HYBRID VEHICLES.pptx
UNIT-V-ELECTRIC AND HYBRID VEHICLES.pptx
 
꧁༒☬ 7042364481 (Call Girl) In Dwarka Delhi Escort Service In Delhi Ncr☬༒꧂
꧁༒☬ 7042364481 (Call Girl) In Dwarka Delhi Escort Service In Delhi Ncr☬༒꧂꧁༒☬ 7042364481 (Call Girl) In Dwarka Delhi Escort Service In Delhi Ncr☬༒꧂
꧁༒☬ 7042364481 (Call Girl) In Dwarka Delhi Escort Service In Delhi Ncr☬༒꧂
 
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGERUNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
UNIT-II-ENGINE AUXILIARY SYSTEMS &TURBOCHARGER
 
如何办理迈阿密大学毕业证(UM毕业证)成绩单留信学历认证原版一比一
如何办理迈阿密大学毕业证(UM毕业证)成绩单留信学历认证原版一比一如何办理迈阿密大学毕业证(UM毕业证)成绩单留信学历认证原版一比一
如何办理迈阿密大学毕业证(UM毕业证)成绩单留信学历认证原版一比一
 
办理学位证(MLU文凭证书)哈勒 维滕贝格大学毕业证成绩单原版一模一样
办理学位证(MLU文凭证书)哈勒 维滕贝格大学毕业证成绩单原版一模一样办理学位证(MLU文凭证书)哈勒 维滕贝格大学毕业证成绩单原版一模一样
办理学位证(MLU文凭证书)哈勒 维滕贝格大学毕业证成绩单原版一模一样
 
Innovating Manufacturing with CNC Technology
Innovating Manufacturing with CNC TechnologyInnovating Manufacturing with CNC Technology
Innovating Manufacturing with CNC Technology
 
VIP Kolkata Call Girl Kasba 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kasba 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kasba 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kasba 👉 8250192130 Available With Room
 
Call Girls in Karachi | +923081633338 | Karachi Call Girls
Call Girls in Karachi  | +923081633338 | Karachi Call GirlsCall Girls in Karachi  | +923081633338 | Karachi Call Girls
Call Girls in Karachi | +923081633338 | Karachi Call Girls
 
Not Sure About VW EGR Valve Health Look For These Symptoms
Not Sure About VW EGR Valve Health Look For These SymptomsNot Sure About VW EGR Valve Health Look For These Symptoms
Not Sure About VW EGR Valve Health Look For These Symptoms
 
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
如何办理(UC毕业证书)堪培拉大学毕业证毕业证成绩单原版一比一
 
( Best ) Genuine Call Girls In Mandi House =DELHI-| 8377087607
( Best ) Genuine Call Girls In Mandi House =DELHI-| 8377087607( Best ) Genuine Call Girls In Mandi House =DELHI-| 8377087607
( Best ) Genuine Call Girls In Mandi House =DELHI-| 8377087607
 
Russian Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
Russian  Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...Russian  Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
Russian Call Girls Delhi Indirapuram {9711199171} Aarvi Gupta ✌️Independent ...
 
Beautiful Vip Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
Beautiful Vip  Call Girls Punjabi Bagh 9711199012 Call /WhatsappsBeautiful Vip  Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
Beautiful Vip Call Girls Punjabi Bagh 9711199012 Call /Whatsapps
 
UNOSAFE ELEVATOR PRIVATE LTD BANGALORE BROUCHER
UNOSAFE ELEVATOR PRIVATE LTD BANGALORE BROUCHERUNOSAFE ELEVATOR PRIVATE LTD BANGALORE BROUCHER
UNOSAFE ELEVATOR PRIVATE LTD BANGALORE BROUCHER
 

lecture 6.pdf

  • 2. One of the most important concepts in object-oriented programming is that of inheritance. Inheritance allows us to define a class in terms of another class, which makes it easier to create and maintain an application. This also provides an opportunity to reuse the code functionality and fast implementation time. When creating a class, instead of writing completely new data members and member functions, the programmer can designate that the new class should inherit the members of an existing class. C++ Inheritance
  • 3. Inheritance is the process by which new classes called derived classes are created from existing classes called base classes. The derived classes have all the features of the base class and the programmer can choose to add new features specific to the newly created derived class. C++ Inheritance
  • 4. “the mechanism by which one class acquires the properties of another class”
  • 5. C++ and inheritance •The language mechanism by which one class acquires the properties (data and operations) of another class •Base Class (or superclass): the class being inherited from •Derived Class (or subclass): the class that inherits
  • 6. Advantages of inheritance •When a class inherits from another class, there are three benefits: •(1) You can reuse the methods and data of the existing class (2) You can extend the existing class by adding new data and new methods (3) You can modify the existing class by overloading its methods with your own implementations
  • 7. Inheritance and accessibility •A class inherits the behavior of another class and enhances it in some way •Inheritance does not mean inheriting access to another class’ private members
  • 8. #include <iostream> class BaseClass { public: BaseClass( ) : baseValue (20) { }; BaseClass(int aValue) : baseValue (aValue) { }; int baseValue; }; class DerivedClass : public BaseClass { public: DerivedClass() : derivedValue (10){ }; DerivedClass(int aDerivedValue) : BaseClass(15), derivedValue(aDerivedValue){ }; int getDerivedValue() { return derivedValue; } private: int derivedValue; }; int main( ) { BaseClass base; DerivedClass child(5); cout << base.baseValue << endl; // will print 20 cout << child.baseValue << endl; // will print 15 cout << child.getDerivedValue() << endl; // will print 5 return 0; }
  • 9. Features or Advantages of Inheritance: Reusability: Inheritance helps the code to be reused in many situations. The base class is defined and once it is compiled, it need not be reworked. Using the concept of inheritance, the programmer can create as many derived classes from the base class as needed while adding specific features to each derived class as needed. C++ Inheritance
  • 10. Features or Advantages of Inheritance: Saves Time and Effort: The above concept of reusability achieved by inheritance saves the programmer time and effort. The main code written can be reused in various situations as needed. Increases Program Structure which results in greater reliability. C++ Inheritance
  • 11. Reminder about public, private and protected access specifiers: 1 If a member or variables defined in a class is private, then they are accessible by members of the same class only and cannot be accessed from outside the class. 2 Public members and variables are accessible from outside the class. 3 Protected access specifier is a stage between private and public. If a member functions or variables defined in a class are protected, then they cannot be accessed from outside the class but can be accessed from the derived class. C++ Inheritance
  • 12. When deriving a class from a base class, the base class may be inherited through public, protected or private inheritance. The type of inheritance is specified by the access- specifier. We hardly use protected or private inheritance, but public inheritance is commonly used. While using different type of inheritance, following rules are applied: Type of Inheritance
  • 13. Public Inheritance: When deriving a class from a public base class, public members of the base class become public members of the derived class and protected members of the base class become protected members of the derived class. A base class's private members are never accessible directly from a derived class, but can be accessed through calls to the public and protected members of the base class. Type of Inheritance
  • 14. Protected Inheritance: When deriving from a protected base class, public and protected members of the base class become protected members of the derived class. Private Inheritance: When deriving from a private base class, public and protected members of the base class become private members of the derived class Type of Inheritance
  • 15. 1. Single class Inheritance: Single inheritance is the one where you have a single base class and a single derived class. Types of Inheritance Class Employee Class Manager It is a Base class (super) it is a sub class (derived)
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. 2. Multilevel Inheritance: In Multi level inheritance, a class inherits its properties from another derived class. Types of Inheritance Class A Class B it is a Base class (super) of B it is a sub class (derived) of A and base class of class C Class C derived class(sub) of class B
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. 3. Multiple Inheritances: In Multiple inheritances, a derived class inherits from multiple base classes. It has properties of both the base classes. Types of Inheritance Class A Class B Base class Class C Derived class
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33. 4. Hierarchical Inheritance: In hierarchical Inheritance, it's like an inverted tree. So multiple classes inherit from a single base class. It's quite analogous to the File system in a unix based system. Types of Inheritance Class A Class B Class C Class D
  • 34.
  • 35.
  • 36.
  • 37.
  • 38. 5. Hybrid Inheritance: In this type of inheritance, we can have mixture of number of inheritances but this can generate an error of using same name function from no of classes, which will bother the compiler to how to use the functions. Therefore, it will generate errors in the program. This has known as ambiguity or duplicity. Ambiguity problem can be solved by using virtual base classes Types of Inheritance
  • 39. Types of Inheritance Class A Class B Class D Class C 5. Hybrid Inheritance:
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.