SlideShare a Scribd company logo
INHERITENCE
SUBMITTED BY:
R.RAMADEVI
M.Sc(CS&IT)
NSCAS
SYNOPSIS
 INHERITANCE DEFINITION
 SYNTAX INACCESS SPECIFIERS
 PUBLIC INHERITANCE
 PROTECTED INHERITANCE
 PRIVATE INHERITANCE
 TYPES OF INHERITANCE
 SINGLE INHERITANCE
 MULIPLE INHERITANCE
 MULITLEVE INHERITANCE
 HIERARCHICAL INHERITANCE
 HYBRID INHERITANCE
 DIAMOND INHERITANCE
INHERITANCE DEFINITION
• Derived quality and characteristics from parents or ancestors
• Like you inherit features of your parents
For example :
“she had inherited the beauty of her Mother”
• Inheritance in object oriented programming can be described as a process of
creating new class from exiting classes
• New classes inheritance some of the properties and behavior of the existing
classes
• An existing class that is “parent” of a new class is called a base class
• New class that inherits properties of the base class is called a derived class
• Inheritance is a technique of code reuse
• It also provides possibility to extend existing classes by creating derived
classes
SYNTAX
• The basic syntax of inheritance is:
class derived class : access specified base class
• Access specified can be public , protected and private
• The default access specified is private
• Access specified affect accessibility of data member of bass class from
the derived class
INHERITANCE ACCESS SPECIFIERS
PUBLIC INHERITANCE
• This inheritance mode is used mostly
• In this the protected member of base class becomes protected members of
derived class and public become public
• Drived class of derived classes:
• If we are inheriting a derived class using a public inheriting as shows below
class B:public A
class C:public B
• Then public and protected members of class A will be accessible in class
C as public and protected respectively
PROTECTED INHERITANCE
• In protected mode the public and protected members of base class
becomes protected members of derived class
Example:
class derived class: protected base class
• If we are inheritance a derived class using a public inheritance as shown
below
class B:protected A
class C:protected B
• Then public and protected member of class
• A will be accessible in class c as protected
PRIVATE INHERITENCE
• In private mode the public and protected member of base class become private members
of derived class
FOR EXAMPLE:
class derived class : private base class
class derived class : base class
• If we are inheriting a derived class using a public inheritance as shows below
FOR EXAMPLE:
class B : private A
class C : private B
TYPES OF INHERITANCE
• There are different type of inheritance
 Single inheritance
Multiple inheritance
Multilevel inheritance
Hierarchical inheritance
Hybrid(virtual) inheritance
SINGLE INHERITANCE
• Single inheritance represents a from of inheritance when there is only one
base class and one derived class
FOR EXAMPLE:
A class describes a person
SINGLE INHERITANCE PROGRAM
• We want to create new class student which should have the same
information as person class plus one new information about uninersity
• In this case we can create a derived should have the same information as
person class plus one new information about university
• we can create a derived class student
• If you want to call the parameterized(user defined)
• Constructor of a base class from a derived class then you need to write a
parameterized constructor of a derived class as below
• We can access member function of base class from a derived class
FOR EXAMPLE:
• We can create a new print() function in a derived class that uses printf()
member function of a base class
MULTIPLE INHERITANCE
Multiple inheritance represents a kind of inheritance when a derived class
inherits properties of multiple classes
FOR EXAMPLE:
• There are three classes A ,Band C and derived class is D as shows below
Class A Class B Class c
Class D
MULTIPLE INHERITANCE PROGRAM
• class derived class : access specified
• base class 1.base class 2..base class n
• You can create a new class that will
• Inherit all the properties of all these
class
SYNTAX
MULTILEVEL INHERITANCE
 Multilevel inheritance represents a type of inheritance when a derived class
is a base class for another class
 In other words deriving a class from a derived class is know as multilevel
inheritance
 Simple multilevel inheritance is shown in below image
 Where class A is a parent of class B and class B is a parent of class C
MULILEVEL INHERITANCE EXAMPLE
• As you can see class person is the base class of both
student employee classes
• At the same time class student is the basic
class for IT student and math student classes
• Employee is the base class for derived and
engineer classes
HIERARCHICAL INHERTANCE
• When there is a need to create multiple derived classes that inheritance
properties of the same base class is known as hierarchical inheritance
EXAMPLE PROGRAM
HYBRID INHERITANCE
• Combination of multilevel and hierarchical inheritance will give you hybrid
inheritance
CLASS A
CLASS B CLASS C
CLASS D
DIAMOND PROBLEM
• When you have a hybrid inheritance then a diamond problem may arise
• In this problem a derived class will have multiple paths to a base
• This will result in duplicate inheritance member of the base class
• This kind of problem is known as diamond problem
DIAMOND DIAGRAM
GRANDPARENT
CHILD 1 CHILD 2
GRANDSONS
VIRTUAL INHERITANCE
Child classes in this case should
inheritance grandparent class by
using Virtual inheritance
THANK YOU!!!

More Related Content

PPTX
Introduction to Inheritance
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
PPTX
Inheritance
PPTX
simple notes Unit 4-Inheritance (2).pptx
PDF
INHERITANCE
PPTX
Ritik (inheritance.cpp)
PPTX
Inheritance
PPTX
Inheritance in oops
Introduction to Inheritance
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
Inheritance
simple notes Unit 4-Inheritance (2).pptx
INHERITANCE
Ritik (inheritance.cpp)
Inheritance
Inheritance in oops

Similar to Inheritance (20)

PDF
OOP Assign No.03(AP).pdf
PPT
E -COMMERCE.ppt
PPT
Inheritance in C++
PDF
Chapter25 inheritance-i
PPTX
Inheritance in OOPS
PDF
chapter-10-inheritance.pdf
PPTX
Inheritance
PPT
Topic inheritance
PPT
Inheritance
DOCX
oop database doc for studevsgdy fdsyn hdf
PPTX
EASY TO LEARN INHERITANCE IN C++
PPTX
Inheritance slides
PDF
PPTX
B.sc CSIT 2nd semester C++ Unit5
PPT
session 24_Inheritance.ppt
PPTX
inheritance in OOPM
PPT
MODULE2_INHERITANCE_SESSION1.ppt computer
PPTX
Inheritance.pptx
PPTX
inheritance_OOPC_datastream.ppttttttttttttttx
PPT
inheritance final ppvjjfjjdrtdyyrtuytyouijkt.ppt
OOP Assign No.03(AP).pdf
E -COMMERCE.ppt
Inheritance in C++
Chapter25 inheritance-i
Inheritance in OOPS
chapter-10-inheritance.pdf
Inheritance
Topic inheritance
Inheritance
oop database doc for studevsgdy fdsyn hdf
EASY TO LEARN INHERITANCE IN C++
Inheritance slides
B.sc CSIT 2nd semester C++ Unit5
session 24_Inheritance.ppt
inheritance in OOPM
MODULE2_INHERITANCE_SESSION1.ppt computer
Inheritance.pptx
inheritance_OOPC_datastream.ppttttttttttttttx
inheritance final ppvjjfjjdrtdyyrtuytyouijkt.ppt
Ad

More from lalithambiga kamaraj (20)

PPTX
Firewall in Network Security
PPTX
Data Compression in Multimedia
PPTX
Data CompressionMultimedia
PPTX
Digital Audio in Multimedia
PPTX
Network Security: Physical security
PPTX
Graphs in Data Structure
PPTX
Package in Java
PPTX
Exception Handling in Java
PPTX
Data structure
PPTX
Digital Image Processing
PPTX
Digital Image Processing
PPTX
Estimating Software Maintenance Costs
PPTX
PPTX
Digital Components
PPTX
Deadlocks in operating system
PPTX
Io management disk scheduling algorithm
PPTX
Recovery system
PPTX
File management
PPTX
Preprocessor
PPTX
Managing console of I/o operations & working with files
Firewall in Network Security
Data Compression in Multimedia
Data CompressionMultimedia
Digital Audio in Multimedia
Network Security: Physical security
Graphs in Data Structure
Package in Java
Exception Handling in Java
Data structure
Digital Image Processing
Digital Image Processing
Estimating Software Maintenance Costs
Digital Components
Deadlocks in operating system
Io management disk scheduling algorithm
Recovery system
File management
Preprocessor
Managing console of I/o operations & working with files
Ad

Recently uploaded (20)

PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
Institutional Correction lecture only . . .
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Basic Mud Logging Guide for educational purpose
PDF
RMMM.pdf make it easy to upload and study
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
Insiders guide to clinical Medicine.pdf
Renaissance Architecture: A Journey from Faith to Humanism
PPH.pptx obstetrics and gynecology in nursing
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Institutional Correction lecture only . . .
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
O7-L3 Supply Chain Operations - ICLT Program
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
Microbial disease of the cardiovascular and lymphatic systems
Abdominal Access Techniques with Prof. Dr. R K Mishra
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Basic Mud Logging Guide for educational purpose
RMMM.pdf make it easy to upload and study
O5-L3 Freight Transport Ops (International) V1.pdf
Final Presentation General Medicine 03-08-2024.pptx
01-Introduction-to-Information-Management.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Insiders guide to clinical Medicine.pdf

Inheritance

  • 2. SYNOPSIS  INHERITANCE DEFINITION  SYNTAX INACCESS SPECIFIERS  PUBLIC INHERITANCE  PROTECTED INHERITANCE  PRIVATE INHERITANCE  TYPES OF INHERITANCE  SINGLE INHERITANCE  MULIPLE INHERITANCE  MULITLEVE INHERITANCE  HIERARCHICAL INHERITANCE  HYBRID INHERITANCE  DIAMOND INHERITANCE
  • 3. INHERITANCE DEFINITION • Derived quality and characteristics from parents or ancestors • Like you inherit features of your parents For example : “she had inherited the beauty of her Mother” • Inheritance in object oriented programming can be described as a process of creating new class from exiting classes • New classes inheritance some of the properties and behavior of the existing classes
  • 4. • An existing class that is “parent” of a new class is called a base class • New class that inherits properties of the base class is called a derived class • Inheritance is a technique of code reuse • It also provides possibility to extend existing classes by creating derived classes
  • 5. SYNTAX • The basic syntax of inheritance is: class derived class : access specified base class • Access specified can be public , protected and private • The default access specified is private • Access specified affect accessibility of data member of bass class from the derived class
  • 6. INHERITANCE ACCESS SPECIFIERS PUBLIC INHERITANCE • This inheritance mode is used mostly • In this the protected member of base class becomes protected members of derived class and public become public • Drived class of derived classes: • If we are inheriting a derived class using a public inheriting as shows below class B:public A class C:public B
  • 7. • Then public and protected members of class A will be accessible in class C as public and protected respectively PROTECTED INHERITANCE • In protected mode the public and protected members of base class becomes protected members of derived class Example: class derived class: protected base class
  • 8. • If we are inheritance a derived class using a public inheritance as shown below class B:protected A class C:protected B • Then public and protected member of class • A will be accessible in class c as protected
  • 9. PRIVATE INHERITENCE • In private mode the public and protected member of base class become private members of derived class FOR EXAMPLE: class derived class : private base class class derived class : base class • If we are inheriting a derived class using a public inheritance as shows below FOR EXAMPLE: class B : private A class C : private B
  • 10. TYPES OF INHERITANCE • There are different type of inheritance  Single inheritance Multiple inheritance Multilevel inheritance Hierarchical inheritance Hybrid(virtual) inheritance
  • 11. SINGLE INHERITANCE • Single inheritance represents a from of inheritance when there is only one base class and one derived class FOR EXAMPLE: A class describes a person
  • 13. • We want to create new class student which should have the same information as person class plus one new information about uninersity • In this case we can create a derived should have the same information as person class plus one new information about university • we can create a derived class student
  • 14. • If you want to call the parameterized(user defined) • Constructor of a base class from a derived class then you need to write a parameterized constructor of a derived class as below • We can access member function of base class from a derived class FOR EXAMPLE: • We can create a new print() function in a derived class that uses printf() member function of a base class
  • 15. MULTIPLE INHERITANCE Multiple inheritance represents a kind of inheritance when a derived class inherits properties of multiple classes FOR EXAMPLE: • There are three classes A ,Band C and derived class is D as shows below Class A Class B Class c Class D
  • 16. MULTIPLE INHERITANCE PROGRAM • class derived class : access specified • base class 1.base class 2..base class n • You can create a new class that will • Inherit all the properties of all these class
  • 18. MULTILEVEL INHERITANCE  Multilevel inheritance represents a type of inheritance when a derived class is a base class for another class  In other words deriving a class from a derived class is know as multilevel inheritance  Simple multilevel inheritance is shown in below image  Where class A is a parent of class B and class B is a parent of class C
  • 20. • As you can see class person is the base class of both student employee classes • At the same time class student is the basic class for IT student and math student classes • Employee is the base class for derived and engineer classes
  • 21. HIERARCHICAL INHERTANCE • When there is a need to create multiple derived classes that inheritance properties of the same base class is known as hierarchical inheritance
  • 23. HYBRID INHERITANCE • Combination of multilevel and hierarchical inheritance will give you hybrid inheritance CLASS A CLASS B CLASS C CLASS D
  • 24. DIAMOND PROBLEM • When you have a hybrid inheritance then a diamond problem may arise • In this problem a derived class will have multiple paths to a base • This will result in duplicate inheritance member of the base class • This kind of problem is known as diamond problem
  • 26. VIRTUAL INHERITANCE Child classes in this case should inheritance grandparent class by using Virtual inheritance