SlideShare a Scribd company logo
INHERITANCE IN C++
INHERITANCE
Inheritance is one of the fundamental features of object-oriented
programming (OOP). It allows you to create new classes that are based on
existing classes, inheriting their properties
TYPES OF INHERITANCE
• Single Inheritance
• Multilevel Inheritance
• Hybrid Inheritance
• Multiple Inheritance
• Hierarchical Inheritance
Base Class (Parent Class)
The class whose properties and behaviors are inherited by other
classes is called the base class or parent class.
It defines the common attributes and functions that can be
shared by its derived classes.
Derived Class (Child Class)
The class that inherits from a base class is called the derived class or child
class.
It can add its own attributes and functions or override the ones inherited
from the base class.
Public inheritance (public access specifier)
All public members of the base class remain public in the derived class,
and protected members of the base class remain protected in the derived
class.
Protected inheritance (protected access specifier)
All public and protected members of the base class become protected in
the derived class.
Private inheritance (private access specifier)
All public and protected members of the base class become private in the
derived class.
Public Inheritance
In this type of inheritance, the public members of the base class remain public in
the derived class, and the protected members of the base class remain
protected in the derived class.
Public members of the base class can be accessed as public members in the
derived class.
Protected Inheritance
In protected inheritance, the public members of the base class become protected
members in the derived class. The protected members of the base class remain
protected in the derived class.
Public members of the base class can be accessed as protected members in the
derived class.
Private Inheritance
In private inheritance, the public members of the base class become private
members in the derived class. The protected members of the base class remain
protected in the derived class.
Public members of the base class can be accessed as private members in the
derived class.
Single inheritance is a fundamental concept that allows a derived class
(also known as a child class) to inherit properties and behaviors from a
single base class (or parent class). It's a way to establish a one-to-one
relationship between classes, creating a hierarchical structure.
Single Inheritance
Multiple Inheritance is a feature of C++ where a class can inherit from
more than one class. i.e. one subclass is inherited from more than
one base class.
Multiple Inheritance
In this type of inheritance, a derived class is created from another
derived class.
Multi-level Inheritance
In this type of inheritance, more than one subclass is inherited from a
single base class. i.e. more than one derived class is created from a single
base class.
Hierarchical
Inheritance
Hybrid Inheritance is implemented by combining more than one type of
inheritance. For example: Combining Hierarchical inheritance and
Multiple Inheritance.
Hybrid (Virtual) Inheritance
Inheritance Ambiguity in C++
when one class is derived from two or more base classes then there may be a
possibility that the base classes have functions with the same name, and the
derived class may not have functions with that name as those of its base classes.
Solution to Ambiguity
ObjectName.ClassName::FunctionName();
AGGRIGATION IN C++
Aggregation is a type of association that represents a "has-a"
relationship between objects. It is a way to model relationships
between classes where one class contains or is composed of
another class as part of its internal structure. Aggregation implies a
weaker relationship than composition
COMPOSITION IN C++
In C++, composition is achieved by including instances of other
classes within a class. This relationship between classes
represents a "has-a" or "whole-part" relationship
THANK YOU
Ad

More Related Content

Similar to Inheritance in C++ (Programming Fundamentals) (20)

Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Ayan Das_25300121057.pptx
Ayan Das_25300121057.pptxAyan Das_25300121057.pptx
Ayan Das_25300121057.pptx
Ayan974999
 
Inheritance in Java - An Introduction & types
Inheritance in Java - An Introduction & typesInheritance in Java - An Introduction & types
Inheritance in Java - An Introduction & types
VijethaChandran
 
Inheritance
InheritanceInheritance
Inheritance
rajshreemuthiah
 
Inheritance
InheritanceInheritance
Inheritance
Aadhi Aadhithya
 
Inheritance
InheritanceInheritance
Inheritance
Amit Dixit
 
E -COMMERCE.ppt
E -COMMERCE.pptE -COMMERCE.ppt
E -COMMERCE.ppt
classall
 
Java(inheritance)
Java(inheritance)Java(inheritance)
Java(inheritance)
Pooja Bhojwani
 
Oop
OopOop
Oop
kaur12345
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
COMSATS Institute of Information Technology
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
HarshitaAshwani
 
Unit 3 Java
Unit 3 JavaUnit 3 Java
Unit 3 Java
arnold 7490
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Paumil Patel
 
inheritance-16031525566nbhij56604452.pdf
inheritance-16031525566nbhij56604452.pdfinheritance-16031525566nbhij56604452.pdf
inheritance-16031525566nbhij56604452.pdf
kashafishfaq21
 
Bethany CR8( kk need for ten idb seen dhi DC
Bethany CR8( kk need for ten idb seen dhi DCBethany CR8( kk need for ten idb seen dhi DC
Bethany CR8( kk need for ten idb seen dhi DC
TSaiteja2
 
Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
preetirawat242004
 
Object Oriented Programming - 7.1. Inheritance
Object Oriented Programming - 7.1. InheritanceObject Oriented Programming - 7.1. Inheritance
Object Oriented Programming - 7.1. Inheritance
AndiNurkholis1
 
Inheritance
InheritanceInheritance
Inheritance
Pranali Chaudhari
 
Programming Lesson by Slidesgo.pptx
Programming Lesson by Slidesgo.pptxProgramming Lesson by Slidesgo.pptx
Programming Lesson by Slidesgo.pptx
DilanAlmsa
 
C++ Inheritance.pptx
C++ Inheritance.pptxC++ Inheritance.pptx
C++ Inheritance.pptx
XanGwaps
 

Recently uploaded (20)

THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx   quiz by Ridip HazarikaTHE STG QUIZ GROUP D.pptx   quiz by Ridip Hazarika
THE STG QUIZ GROUP D.pptx quiz by Ridip Hazarika
Ridip Hazarika
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFAExercise Physiology MCQS By DR. NASIR MUSTAFA
Exercise Physiology MCQS By DR. NASIR MUSTAFA
Dr. Nasir Mustafa
 
03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.03#UNTAGGED. Generosity in architecture.
03#UNTAGGED. Generosity in architecture.
MCH
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
Link your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRMLink your Lead Opportunities into Spreadsheet using odoo CRM
Link your Lead Opportunities into Spreadsheet using odoo CRM
Celine George
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Introduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe EngineeringIntroduction to Vibe Coding and Vibe Engineering
Introduction to Vibe Coding and Vibe Engineering
Damian T. Gordon
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
"Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules""Basics of Heterocyclic Compounds and Their Naming Rules"
"Basics of Heterocyclic Compounds and Their Naming Rules"
rupalinirmalbpharm
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
To study the nervous system of insect.pptx
To study the nervous system of insect.pptxTo study the nervous system of insect.pptx
To study the nervous system of insect.pptx
Arshad Shaikh
 
Ad

Inheritance in C++ (Programming Fundamentals)

  • 2. INHERITANCE Inheritance is one of the fundamental features of object-oriented programming (OOP). It allows you to create new classes that are based on existing classes, inheriting their properties TYPES OF INHERITANCE • Single Inheritance • Multilevel Inheritance • Hybrid Inheritance • Multiple Inheritance • Hierarchical Inheritance
  • 3. Base Class (Parent Class) The class whose properties and behaviors are inherited by other classes is called the base class or parent class. It defines the common attributes and functions that can be shared by its derived classes. Derived Class (Child Class) The class that inherits from a base class is called the derived class or child class. It can add its own attributes and functions or override the ones inherited from the base class.
  • 4. Public inheritance (public access specifier) All public members of the base class remain public in the derived class, and protected members of the base class remain protected in the derived class. Protected inheritance (protected access specifier) All public and protected members of the base class become protected in the derived class. Private inheritance (private access specifier) All public and protected members of the base class become private in the derived class.
  • 5. Public Inheritance In this type of inheritance, the public members of the base class remain public in the derived class, and the protected members of the base class remain protected in the derived class. Public members of the base class can be accessed as public members in the derived class. Protected Inheritance In protected inheritance, the public members of the base class become protected members in the derived class. The protected members of the base class remain protected in the derived class. Public members of the base class can be accessed as protected members in the derived class. Private Inheritance In private inheritance, the public members of the base class become private members in the derived class. The protected members of the base class remain protected in the derived class. Public members of the base class can be accessed as private members in the derived class.
  • 6. Single inheritance is a fundamental concept that allows a derived class (also known as a child class) to inherit properties and behaviors from a single base class (or parent class). It's a way to establish a one-to-one relationship between classes, creating a hierarchical structure. Single Inheritance
  • 7. Multiple Inheritance is a feature of C++ where a class can inherit from more than one class. i.e. one subclass is inherited from more than one base class. Multiple Inheritance
  • 8. In this type of inheritance, a derived class is created from another derived class. Multi-level Inheritance
  • 9. In this type of inheritance, more than one subclass is inherited from a single base class. i.e. more than one derived class is created from a single base class. Hierarchical Inheritance
  • 10. Hybrid Inheritance is implemented by combining more than one type of inheritance. For example: Combining Hierarchical inheritance and Multiple Inheritance. Hybrid (Virtual) Inheritance
  • 11. Inheritance Ambiguity in C++ when one class is derived from two or more base classes then there may be a possibility that the base classes have functions with the same name, and the derived class may not have functions with that name as those of its base classes. Solution to Ambiguity ObjectName.ClassName::FunctionName();
  • 12. AGGRIGATION IN C++ Aggregation is a type of association that represents a "has-a" relationship between objects. It is a way to model relationships between classes where one class contains or is composed of another class as part of its internal structure. Aggregation implies a weaker relationship than composition COMPOSITION IN C++ In C++, composition is achieved by including instances of other classes within a class. This relationship between classes represents a "has-a" or "whole-part" relationship