SlideShare a Scribd company logo
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 1
Haresh Jaiswal
Rising Technologies, Jalna.
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 2
Introduction
 Inheritance allows us to extend the definition of a class without
making any physical changes to the existing class.
 Inheritance lets you create new classes reusing some features
from existing class.
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 3
Introduction
 Any new class that you create from an existing class is
called derived class & existing class is called as base class.
A
B
Base Class
Derived
Class
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 4
Introduction
 The inheritance enables a derived class to inherit features from
its base class. Furthermore, the derived class can add new
features of its own.
A
B
void show()
{
}
void show()
{
}
void print()
{
}
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 5
Introduction
 Therefore, rather than to create a completely new class from
scratch, you can take advantage of inheritance and reduce
software complexity.
A
B
void show()
{
}
void show()
{
}
void print()
{
}
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 6
Inheritance
Class Bird
Non Flying BirdFlying Bird
Robin Swallow Penguin Kiwi
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 7
Inheritance
 The concept of inheritance provides the idea of reusability. This
means that we can add additional features to an existing class
without modifying it.
A
B
void show()
{
}
void show()
{
}
void print()
{
}
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 8
Inheritance
 Inheritance is the process by which objects of one class acquire
properties of another class. It supports the concepts of
hierarchical classification.
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 9
Forms/Types of Inheritance
 Single Inheritance
 Multiple Inheritance
 Multi-Level Inheritance
 Hierarchical Inheritance
 Hybrid Inheritance
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 10
Single Inheritance
 It is the inheritance hierarchy wherein a derived class inherits
from only one base class.
Class A
Class B
Base Class
Derived Class
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 11
Multiple Inheritance
 It is the inheritance hierarchy wherein a derived class inherits
from multiple base classes.
Class BClass A
Class C
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 12
Multi Level Inheritance
 It is the inheritance hierarchy wherein subclass acts as a base
class for other classes.
Class B
Class A
Class C
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 13
Hierarchical Inheritance
 It is the inheritance hierarchy wherein multiple subclasses inherit
from one base class.
Class B
Class A
Class C
Class D Class E
Class D
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 14
Hybrid Inheritance
 The inheritance hierarchy that reflects any legal combination of
other four types of inheritance.
Class B
Class A
Class C
Class D
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 15
Defining Derived Class
 Derived class can be defined by specifying its relationship with
the base class in addition to its own details.
 In order to derive a class from another, we use a colon (:) in the
declaration of the derived class using the following format.
class Derived_Class : VisiblityModifier Base_Class
{
...
...
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 16
Defining Derived Class
 Where Derived_Class is the name of the derived class and
Base_Class is the name of the class on which it is based.
class Derived_Class : VisiblityModifier Base_Class
{
...
...
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 17
Defining Derived Class
 The VisiblityModifier is optional, and if present it may be
 public
 protected
 private.
 It describes the access level for the members that are inherited from
the base class.
class Derived_Class : VisiblityModifier Base_Class
{
...
...
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 18
Defining Derived Class
 If VisiblityModifier is not specified then default visibility is
private.
class Derived_Class : Base_Class
{
...
...
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 19
Defining Derived Class
 A class can have members under following 3 visibilities
 Public
 Protected
 Private
 In inheritance, public & protected members of base class gets
inherited into derived class.
 But private members of base class are inaccessible to derived
class.
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 20
Public Derivation
class Abc
{
// members of ABC
};
class Xyz : public Abc
{
// members of XYZ
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 21
Private Derivation
class Abc
{
// members of ABC
};
class Xyz : private Abc
{
// members of XYZ
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 22
Protected Derivation
class Abc
{
// members of ABC
};
class Xyz : protected Abc
{
// members of XYZ
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 23
Default Private Derivation
class Abc
{
// members of ABC
};
class Xyz : Abc
{
// members of XYZ
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 24
Private Visibility Mode
 When a base class is privately inherited by a derived class,
 All public & protected members of base class becomes private
members of derived class.
 No private member of base class will be accessible by derived class.
 In this case the public as well as protected members of base class
can be accessed by the member functions of derived class.
 But no member of base class can be accessed by object of
derived class.
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 25
Public Visibility Mode
 When a base class is publicly inherited by a derived class,
 all public members of base class becomes public members of
derived class.
 all protected members of base class will become protected
members of derived class.
 No private member of base class will be accessible by derived class.
 In this case the public members of base class can be accessed via
object of derived class.
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 26
Protected Visibility Mode
 C++ Provides a third visibility modifier ‘protected’, which serve a
limited purpose in inheritance.
 A member declared as protected is accessible by the member
functions within its class and any class immediately derived from
it.
 It cannot be accessed by the functions outside these two classes.
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 27
Protected Visibility Mode
 When a base class is protectedly inherited by a derived class,
 all public & protected members of base class becomes protected
members of derived class.
 No private member of base class will be accessible by derived class.
 In this case no members of base class can be accessed via object
of derived class.
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 28
Visibility Modes
class ABC
{
private: //optional
//accessible to member functions within this class only.
protected:
//accessible to member functions within this class and
derived class only.
public:
//accessible to all functions within the program.
};
Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 29
Private
Protected
Public
Private
Protected
Public
Private
Protected
Public
Private
Protected
Public
Not InheritableNot Inheritable
Class B : Public A
Class A
Class C : Private A
Class X : Protected B

More Related Content

What's hot

Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
Prabhu D
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
Sidd Singh
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
Abed Bukhari
 
66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
Laura Popovici
 

What's hot (19)

C++ Inheritance
C++ InheritanceC++ Inheritance
C++ Inheritance
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Kotlin
KotlinKotlin
Kotlin
 
Constructor and destructor in C++
Constructor and destructor in C++Constructor and destructor in C++
Constructor and destructor in C++
 
Qno 2 (a)
Qno 2 (a)Qno 2 (a)
Qno 2 (a)
 
Constructors destructors
Constructors destructorsConstructors destructors
Constructors destructors
 
Unlocking the Magic of Monads with Java 8
Unlocking the Magic of Monads with Java 8Unlocking the Magic of Monads with Java 8
Unlocking the Magic of Monads with Java 8
 
Cs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUALCs2312 OOPS LAB MANUAL
Cs2312 OOPS LAB MANUAL
 
Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++Support for Object-Oriented Programming (OOP) in C++
Support for Object-Oriented Programming (OOP) in C++
 
Introduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutletIntroduction to classes the concept of a class/tutorialoutlet
Introduction to classes the concept of a class/tutorialoutlet
 
friends functionToshu
friends functionToshufriends functionToshu
friends functionToshu
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
A (too) Short Introduction to Scala
A (too) Short Introduction to ScalaA (too) Short Introduction to Scala
A (too) Short Introduction to Scala
 
Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)Inheritance, polymorphisam, abstract classes and composition)
Inheritance, polymorphisam, abstract classes and composition)
 
Csharp4 objects and_types
Csharp4 objects and_typesCsharp4 objects and_types
Csharp4 objects and_types
 
Java - Generic programming
Java - Generic programmingJava - Generic programming
Java - Generic programming
 
Learning C++ - Class 4
Learning C++ - Class 4Learning C++ - Class 4
Learning C++ - Class 4
 
66781291 java-lab-manual
66781291 java-lab-manual66781291 java-lab-manual
66781291 java-lab-manual
 

Viewers also liked

Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
Princess Sam
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
Princess Sam
 
file handling c++
file handling c++file handling c++
file handling c++
Guddu Spy
 

Viewers also liked (20)

01. introduction to C++
01. introduction to C++01. introduction to C++
01. introduction to C++
 
08. handling file streams
08. handling file streams08. handling file streams
08. handling file streams
 
07. Virtual Functions
07. Virtual Functions07. Virtual Functions
07. Virtual Functions
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
 
Managing console
Managing consoleManaging console
Managing console
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Virtual function
Virtual functionVirtual function
Virtual function
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
 
file handling c++
file handling c++file handling c++
file handling c++
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
Bca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloadingBca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloading
 
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
Lecture 7, c++(complete reference,herbet sheidt)chapter-17.
 
16 virtual function
16 virtual function16 virtual function
16 virtual function
 
Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++Abstract Base Class and Polymorphism in C++
Abstract Base Class and Polymorphism in C++
 
pointers,virtual functions and polymorphism
pointers,virtual functions and polymorphismpointers,virtual functions and polymorphism
pointers,virtual functions and polymorphism
 
C++ ppt
C++ pptC++ ppt
C++ ppt
 

Similar to 05. inheritance

Inheritance_abstractclass_interface.pdf
Inheritance_abstractclass_interface.pdfInheritance_abstractclass_interface.pdf
Inheritance_abstractclass_interface.pdf
kshitijsaini9
 

Similar to 05. inheritance (20)

lecture 6.pdf
lecture 6.pdflecture 6.pdf
lecture 6.pdf
 
6 Inheritance
6 Inheritance6 Inheritance
6 Inheritance
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance
InheritanceInheritance
Inheritance
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
Inheritance_abstractclass_interface.pdf
Inheritance_abstractclass_interface.pdfInheritance_abstractclass_interface.pdf
Inheritance_abstractclass_interface.pdf
 
Inheritance chepter 7
Inheritance chepter 7Inheritance chepter 7
Inheritance chepter 7
 
Mca 2nd sem u-3 inheritance
Mca 2nd  sem u-3 inheritanceMca 2nd  sem u-3 inheritance
Mca 2nd sem u-3 inheritance
 
Lecturespecial
LecturespecialLecturespecial
Lecturespecial
 
OOP
OOPOOP
OOP
 
Inheritance
Inheritance Inheritance
Inheritance
 
MODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computerMODULE2_INHERITANCE_SESSION1.ppt computer
MODULE2_INHERITANCE_SESSION1.ppt computer
 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptxinheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
 
Bca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritanceBca 2nd sem u-3 inheritance
Bca 2nd sem u-3 inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 

Recently uploaded

Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 

Recently uploaded (20)

Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
Extraction Of Natural Dye From Beetroot (Beta Vulgaris) And Preparation Of He...
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)Template Jadual Bertugas Kelas (Boleh Edit)
Template Jadual Bertugas Kelas (Boleh Edit)
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptxSolid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
Solid waste management & Types of Basic civil Engineering notes by DJ Sir.pptx
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
50 ĐỀ LUYỆN THI IOE LỚP 9 - NĂM HỌC 2022-2023 (CÓ LINK HÌNH, FILE AUDIO VÀ ĐÁ...
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Fish and Chips - have they had their chips
Fish and Chips - have they had their chipsFish and Chips - have they had their chips
Fish and Chips - have they had their chips
 

05. inheritance

  • 1. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 1 Haresh Jaiswal Rising Technologies, Jalna.
  • 2. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 2 Introduction  Inheritance allows us to extend the definition of a class without making any physical changes to the existing class.  Inheritance lets you create new classes reusing some features from existing class.
  • 3. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 3 Introduction  Any new class that you create from an existing class is called derived class & existing class is called as base class. A B Base Class Derived Class
  • 4. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 4 Introduction  The inheritance enables a derived class to inherit features from its base class. Furthermore, the derived class can add new features of its own. A B void show() { } void show() { } void print() { }
  • 5. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 5 Introduction  Therefore, rather than to create a completely new class from scratch, you can take advantage of inheritance and reduce software complexity. A B void show() { } void show() { } void print() { }
  • 6. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 6 Inheritance Class Bird Non Flying BirdFlying Bird Robin Swallow Penguin Kiwi
  • 7. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 7 Inheritance  The concept of inheritance provides the idea of reusability. This means that we can add additional features to an existing class without modifying it. A B void show() { } void show() { } void print() { }
  • 8. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 8 Inheritance  Inheritance is the process by which objects of one class acquire properties of another class. It supports the concepts of hierarchical classification.
  • 9. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 9 Forms/Types of Inheritance  Single Inheritance  Multiple Inheritance  Multi-Level Inheritance  Hierarchical Inheritance  Hybrid Inheritance
  • 10. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 10 Single Inheritance  It is the inheritance hierarchy wherein a derived class inherits from only one base class. Class A Class B Base Class Derived Class
  • 11. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 11 Multiple Inheritance  It is the inheritance hierarchy wherein a derived class inherits from multiple base classes. Class BClass A Class C
  • 12. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 12 Multi Level Inheritance  It is the inheritance hierarchy wherein subclass acts as a base class for other classes. Class B Class A Class C
  • 13. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 13 Hierarchical Inheritance  It is the inheritance hierarchy wherein multiple subclasses inherit from one base class. Class B Class A Class C Class D Class E Class D
  • 14. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 14 Hybrid Inheritance  The inheritance hierarchy that reflects any legal combination of other four types of inheritance. Class B Class A Class C Class D
  • 15. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 15 Defining Derived Class  Derived class can be defined by specifying its relationship with the base class in addition to its own details.  In order to derive a class from another, we use a colon (:) in the declaration of the derived class using the following format. class Derived_Class : VisiblityModifier Base_Class { ... ... };
  • 16. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 16 Defining Derived Class  Where Derived_Class is the name of the derived class and Base_Class is the name of the class on which it is based. class Derived_Class : VisiblityModifier Base_Class { ... ... };
  • 17. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 17 Defining Derived Class  The VisiblityModifier is optional, and if present it may be  public  protected  private.  It describes the access level for the members that are inherited from the base class. class Derived_Class : VisiblityModifier Base_Class { ... ... };
  • 18. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 18 Defining Derived Class  If VisiblityModifier is not specified then default visibility is private. class Derived_Class : Base_Class { ... ... };
  • 19. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 19 Defining Derived Class  A class can have members under following 3 visibilities  Public  Protected  Private  In inheritance, public & protected members of base class gets inherited into derived class.  But private members of base class are inaccessible to derived class.
  • 20. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 20 Public Derivation class Abc { // members of ABC }; class Xyz : public Abc { // members of XYZ };
  • 21. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 21 Private Derivation class Abc { // members of ABC }; class Xyz : private Abc { // members of XYZ };
  • 22. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 22 Protected Derivation class Abc { // members of ABC }; class Xyz : protected Abc { // members of XYZ };
  • 23. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 23 Default Private Derivation class Abc { // members of ABC }; class Xyz : Abc { // members of XYZ };
  • 24. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 24 Private Visibility Mode  When a base class is privately inherited by a derived class,  All public & protected members of base class becomes private members of derived class.  No private member of base class will be accessible by derived class.  In this case the public as well as protected members of base class can be accessed by the member functions of derived class.  But no member of base class can be accessed by object of derived class.
  • 25. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 25 Public Visibility Mode  When a base class is publicly inherited by a derived class,  all public members of base class becomes public members of derived class.  all protected members of base class will become protected members of derived class.  No private member of base class will be accessible by derived class.  In this case the public members of base class can be accessed via object of derived class.
  • 26. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 26 Protected Visibility Mode  C++ Provides a third visibility modifier ‘protected’, which serve a limited purpose in inheritance.  A member declared as protected is accessible by the member functions within its class and any class immediately derived from it.  It cannot be accessed by the functions outside these two classes.
  • 27. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 27 Protected Visibility Mode  When a base class is protectedly inherited by a derived class,  all public & protected members of base class becomes protected members of derived class.  No private member of base class will be accessible by derived class.  In this case no members of base class can be accessed via object of derived class.
  • 28. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 28 Visibility Modes class ABC { private: //optional //accessible to member functions within this class only. protected: //accessible to member functions within this class and derived class only. public: //accessible to all functions within the program. };
  • 29. Rising Technologies, Jalna (MH). + 91 9423156065, http://www.RisingTechnologies.in 29 Private Protected Public Private Protected Public Private Protected Public Private Protected Public Not InheritableNot Inheritable Class B : Public A Class A Class C : Private A Class X : Protected B