SlideShare a Scribd company logo
6
Most read
10
Most read
11
Most read
C++ Inheritance
PPT Presentation on topic
Prepared by:
Asst. prof. Nida Ansari
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. This existing class is called
the base class, and the new class is referred to as
the derived 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
General Format for implementing the concept of Inheritance:
class derived_classname: access specifier
baseclassname
For example, if the base class is MyClass and the derived
class is sample it is specified as:
class sample: public MyClass
The above makes sample have access to both public and
protected variables of base class MyClass
C++ Inheritance
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
Inheritance Example:
class MyClass
{ public:
MyClass(void) { x=0; }
void f(int n1)
{ x= n1*5;}
void output(void) { cout<<x; }
private:
int x;
};
C++ Inheritance
Inheritance Example:
class sample: public MyClass
{ public:
sample(void) { s1=0; }
void f1(int n1)
{ s1=n1*10;}
void output(void)
{ MyClass::output(); cout << s1; }
private:
int s1;
};
C++ Inheritance
Inheritance Example:
int main(void)
{ sample s;
s.f(10);
s.output();
s.f1(20);
s.output();
}
The output of the above program is
50
200
C++ 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:
Inheritance and its types  explained.ppt
Inheritance and its types  explained.ppt

More Related Content

PPT
6 Inheritance
Praveen M Jigajinni
 
ODP
Ppt of c++ vs c#
shubhra chauhan
 
PPTX
Inheritance
zindadili
 
PPTX
Inheritance
Burhan Ahmed
 
PDF
chapter-10-inheritance.pdf
study material
 
PDF
Chapter 6 and inheritance OOP C++ tu ioe
EZERR1
 
PPTX
Opp concept in c++
SadiqullahGhani1
 
PPTX
C++ presentation
SudhanshuVijay3
 
6 Inheritance
Praveen M Jigajinni
 
Ppt of c++ vs c#
shubhra chauhan
 
Inheritance
zindadili
 
Inheritance
Burhan Ahmed
 
chapter-10-inheritance.pdf
study material
 
Chapter 6 and inheritance OOP C++ tu ioe
EZERR1
 
Opp concept in c++
SadiqullahGhani1
 
C++ presentation
SudhanshuVijay3
 

Similar to Inheritance and its types explained.ppt (20)

PDF
Xamarin: Namespace and Classes
Eng Teong Cheah
 
PDF
C++ Version 2
JIGAR MAKHIJA
 
PPTX
Inheritance in c++
Vishal Patil
 
DOCX
Introduction to object oriented programming concepts
Ganesh Karthik
 
PDF
Inheritance
Pranali Chaudhari
 
PPSX
Support for Object-Oriented Programming (OOP) in C++
Ameen Sha'arawi
 
PPTX
Object Oriented Programming using C++(UNIT 1)
Dr. SURBHI SAROHA
 
PDF
C++ largest no between three nos
krismishra
 
PPTX
Inheritance & interface ppt Inheritance
narikamalliy
 
PPTX
Object Oriented Programming using c++.pptx
olisahchristopher
 
PPTX
Inheritance and Interfaces
NAGASURESH MANOHARAN
 
PDF
Inheritance and interface
Shubham Sharma
 
PPTX
Interfaces c#
Nipam Medhi
 
PDF
Object Oriented Programming notes provided
dummydoona
 
PPT
Java oops PPT
kishu0005
 
PPTX
‫Chapter3 inheritance
Mahmoud Alfarra
 
PPTX
Inheritance (with classifications)
Redwan Islam
 
DOCX
I assignmnt(oops)
Jay Patel
 
PDF
lecture 6.pdf
WaqarRaj1
 
PPTX
Chap-3 Inheritance.pptx
chetanpatilcp783
 
Xamarin: Namespace and Classes
Eng Teong Cheah
 
C++ Version 2
JIGAR MAKHIJA
 
Inheritance in c++
Vishal Patil
 
Introduction to object oriented programming concepts
Ganesh Karthik
 
Inheritance
Pranali Chaudhari
 
Support for Object-Oriented Programming (OOP) in C++
Ameen Sha'arawi
 
Object Oriented Programming using C++(UNIT 1)
Dr. SURBHI SAROHA
 
C++ largest no between three nos
krismishra
 
Inheritance & interface ppt Inheritance
narikamalliy
 
Object Oriented Programming using c++.pptx
olisahchristopher
 
Inheritance and Interfaces
NAGASURESH MANOHARAN
 
Inheritance and interface
Shubham Sharma
 
Interfaces c#
Nipam Medhi
 
Object Oriented Programming notes provided
dummydoona
 
Java oops PPT
kishu0005
 
‫Chapter3 inheritance
Mahmoud Alfarra
 
Inheritance (with classifications)
Redwan Islam
 
I assignmnt(oops)
Jay Patel
 
lecture 6.pdf
WaqarRaj1
 
Chap-3 Inheritance.pptx
chetanpatilcp783
 
Ad

Recently uploaded (20)

PDF
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
PPTX
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
PDF
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PPTX
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
ACUTE NASOPHARYNGITIS. pptx
AneetaSharma15
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
Module 3: Health Systems Tutorial Slides S2 2025
Jonathan Hallett
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Nursing Management of Patients with Disorders of Ear, Nose, and Throat (ENT) ...
RAKESH SAJJAN
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
NOI Hackathon - Summer Edition - GreenThumber.pptx
MartinaBurlando1
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
Presentation on Janskhiya sthirata kosh.
Ms Usha Vadhel
 
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Miraj Khan
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Types of Literary Text: Poetry and Prose
kaelandreabibit
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Ad

Inheritance and its types explained.ppt

  • 1. C++ Inheritance PPT Presentation on topic Prepared by: Asst. prof. Nida Ansari
  • 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. This existing class is called the base class, and the new class is referred to as the derived 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. General Format for implementing the concept of Inheritance: class derived_classname: access specifier baseclassname For example, if the base class is MyClass and the derived class is sample it is specified as: class sample: public MyClass The above makes sample have access to both public and protected variables of base class MyClass C++ Inheritance
  • 5. 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
  • 6. Inheritance Example: class MyClass { public: MyClass(void) { x=0; } void f(int n1) { x= n1*5;} void output(void) { cout<<x; } private: int x; }; C++ Inheritance
  • 7. Inheritance Example: class sample: public MyClass { public: sample(void) { s1=0; } void f1(int n1) { s1=n1*10;} void output(void) { MyClass::output(); cout << s1; } private: int s1; }; C++ Inheritance
  • 8. Inheritance Example: int main(void) { sample s; s.f(10); s.output(); s.f1(20); s.output(); } The output of the above program is 50 200 C++ Inheritance
  • 9. 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)
  • 10. 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
  • 11. 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
  • 12. 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
  • 13. 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
  • 14. Types of Inheritance Class A Class B Class D Class C 5. Hybrid Inheritance: