SlideShare a Scribd company logo
NAME - RITIK
ROLL NO. - UE198077
SUBJECT - PROGRAMMING FUNDAMENTAL
SUBMITTED TO - SUKHVIR SIR
TOPIC - INHERITANCE: EXTENDING CLASSES
B.E.(IT),1st year
Inheritance:
 The mechanism of deriving a new class from an old one is called Inheritance.
 The old class is referred to as the base class.
 The new one is called the derived class or subclass.
General form of defining a derived class
Syntax:
Class derived-class-name : visibility mode base-class-name
{
……..//
…….// members of derived class
…….//
};
The colon indicate that the derived-class-name is derived from the base-class-name. The visibility mode is
optional and, if present, may be either private or public. The default visibility mode is private.
Visibility mode specifies whether the features of the base class are privately derived or publicly derived.
Types of Inheritance
 Single Inheritance
 Multiple Inheritance
 Hierarchical Inheritance
 Multilevel Inheritance
 Hybrid Inheritance
Single Inheritance
 In single inheritance there exists single
base class and single derived class.
 It is the most simplest form of
inheritance.
Example of single inheritance
Output
Multiple inheritance
 Multiple inheritance occurs when a class
is inherit from more than one base class.
 Derived class can inherit features from
multiple base classes using multiple
inheritance.
Example of multiple inheritance
Output
Hierarchical inheritance
In this type of inheritance, more than one sub
class is inherited from a single base class. i.e.
more than one derived class is created from a
single base class.
Example of hierarchical inheritance
Output
Multilevel inheritance
In this type of inheritance, a derived class is
created from another derived class.
The class C serves as a base class for the
derived class B, which in turn serves as a base
class for the derived class A. The class B as
intermediate base class since it provides a link
for the inheritance between A and C the chain
ABC is known as inheritance path.
Class C {………}; //base class
Class B: public C {………}; //B derived from C
Class A: public B {……}; //A derived form B
Example of Multilevel inheritance
Output
Hybrid inheritance
Hybrid inheritance is implemented by
combining more than one type of
inheritance. For example: combining
hierarchical inheritance and multiple
inheritance.
Example of Hybrid inheritance
Output
Virtual base class
Consider a situation where three kind of inheritance, namely, multilevel, multiple and
hierarchical inheritance, are involved. This is illustrated in the figure.
The ‘child’ has two direct base classes ‘parent1’ and
‘Parent2’ which themselves have a common base class
‘grand parent’. The ‘child’ inherits the traits of ‘grandparent’
via two separate paths. It can also inherits the base class
directly. The ‘grand parent’ is sometimes referred to as the indirect base class.
This means ‘child’ is inherit the same property twice. To remove this duplication we
declare the base class ‘grandparent’ as the virtual while declaring the direct or
intermediate base class as shown:
Syntax
class A //grandparent
{ …….};
Class B1:virtual public A //parent1
{……..};
Class B2:public virtual A //parent2
{…….};
Class C:public B1,public B2 //child
{…….}; //only one copy of A will be inherited
Abstract classes
An abstract class is one that is not used to create objects. An abstract class is
designed only to act as a base class (to be inherited by other classes). It is a design
concept in program development and provides a base upon which other classes may
be built.
The concept can be explained through a simple example of an abstract base class
vehicle which may be declared in a program for deriving LMV (light motor vehicle),HMV
(heavy motor vehicle) and TW(two wheeler) derived classes. A pure virtual function
spec() may be set the specification of LMV as per its four wheel and smaller engine
and that of HMV as per its eight or more wheels and relatively larger engine.
Example
Class vehicle //abstract base class
{ private:
Datatype d1,d2;
public:
virtual void spec()=0; //pure virtual funtion
};
Class LMV : public vehicle
{ public:
void spec(){ ……. } //LMV definition of spec function
};
Example
Class HMV : public vehicle
{ public:
void spec(){ …….. } HMV definition of spec function
};
Class TW : public vehicle
{ public:
void spec(){ …….. } //TW definition of spec function
};
Advantages of inheritance
 Inheritance promote reusability. When a class inherits or derives another class, it
can access all functionality of inherited class.
 Reusability enhanced reliability. the base class code is already tested and
debugged.
 Inheritance helps to reduce code redundancy and supports code extensibility.
Disadvantages of inheritance
 Inherited functions work slower than the normal function as there is indirection.
 Improper use of inheritance lead to wrong solution.
 Inheritance increases the coupling between base class and derived class. A change
in base class will affects all the child classes.
Ritik (inheritance.cpp)

More Related Content

PPT
Inheritance
PPTX
Introduction to Inheritance
PPTX
Inheritance in OOPS
PPT
Inheritance
PPTX
Single inheritance
PPTX
Inheritance in Object Oriented Programming
PPTX
Inheritance In C++ (Object Oriented Programming)
PPS
Inheritance
Inheritance
Introduction to Inheritance
Inheritance in OOPS
Inheritance
Single inheritance
Inheritance in Object Oriented Programming
Inheritance In C++ (Object Oriented Programming)
Inheritance

What's hot (20)

PDF
Inheritance
PDF
Inheritance chapter-6-computer-science-with-c++ opt
PPTX
Multiple inheritance in c++
PPTX
Inheritance in c++ part1
PPTX
Oop inheritance
PPT
Inheritance, Object Oriented Programming
PPT
inhertance c++
PPT
Inheritance in C++
PPT
Inheritance in C++
PPT
PPTX
Inheritance in c++
PDF
Inheritance access specifier in oop
PDF
Inheritance
PPTX
Inheritance in oops
PPTX
Inheritance
PPT
Inheritance
PPT
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
PPTX
Inheritance
PDF
C++ Multiple Inheritance
Inheritance
Inheritance chapter-6-computer-science-with-c++ opt
Multiple inheritance in c++
Inheritance in c++ part1
Oop inheritance
Inheritance, Object Oriented Programming
inhertance c++
Inheritance in C++
Inheritance in C++
Inheritance in c++
Inheritance access specifier in oop
Inheritance
Inheritance in oops
Inheritance
Inheritance
Inheritance in c++ ppt (Powerpoint) | inheritance in c++ ppt presentation | i...
Inheritance
C++ Multiple Inheritance
Ad

Similar to Ritik (inheritance.cpp) (20)

PPTX
Week 8 - OOP Inheritance11111111111.pptx
PPTX
Inheritance in c++ by Manan Pasricha
PPT
MODULE2_INHERITANCE_SESSION1.ppt computer
PDF
PDF
Inheritance
PPT
Inheritance.ppt
PPT
E -COMMERCE.ppt
PDF
chapter-10-inheritance.pdf
PPTX
Inheritance
PPTX
Inheritance (with classifications)
PPTX
Inheritance
PPT
Inheritance OOP Concept in C++.
PPTX
iheritence.pptx
PPTX
Inheritance
PPT
inheritence
PDF
lecture 6.pdf
PPSX
PPT
11 Inheritance.ppt
PPTX
Inheritance
PPSX
Inheritance and Polymorphism in Oops
Week 8 - OOP Inheritance11111111111.pptx
Inheritance in c++ by Manan Pasricha
MODULE2_INHERITANCE_SESSION1.ppt computer
Inheritance
Inheritance.ppt
E -COMMERCE.ppt
chapter-10-inheritance.pdf
Inheritance
Inheritance (with classifications)
Inheritance
Inheritance OOP Concept in C++.
iheritence.pptx
Inheritance
inheritence
lecture 6.pdf
11 Inheritance.ppt
Inheritance
Inheritance and Polymorphism in Oops
Ad

Recently uploaded (20)

PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Lecture Notes Electrical Wiring System Components
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
DOCX
573137875-Attendance-Management-System-original
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
Current and future trends in Computer Vision.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Foundation to blockchain - A guide to Blockchain Tech
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Geodesy 1.pptx...............................................
Operating System & Kernel Study Guide-1 - converted.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
additive manufacturing of ss316l using mig welding
Lecture Notes Electrical Wiring System Components
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Automation-in-Manufacturing-Chapter-Introduction.pdf
573137875-Attendance-Management-System-original
CYBER-CRIMES AND SECURITY A guide to understanding
Current and future trends in Computer Vision.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Internet of Things (IOT) - A guide to understanding
Foundation to blockchain - A guide to Blockchain Tech
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
R24 SURVEYING LAB MANUAL for civil enggi
Model Code of Practice - Construction Work - 21102022 .pdf
Geodesy 1.pptx...............................................

Ritik (inheritance.cpp)

  • 1. NAME - RITIK ROLL NO. - UE198077 SUBJECT - PROGRAMMING FUNDAMENTAL SUBMITTED TO - SUKHVIR SIR TOPIC - INHERITANCE: EXTENDING CLASSES B.E.(IT),1st year
  • 2. Inheritance:  The mechanism of deriving a new class from an old one is called Inheritance.  The old class is referred to as the base class.  The new one is called the derived class or subclass.
  • 3. General form of defining a derived class Syntax: Class derived-class-name : visibility mode base-class-name { ……..// …….// members of derived class …….// }; The colon indicate that the derived-class-name is derived from the base-class-name. The visibility mode is optional and, if present, may be either private or public. The default visibility mode is private. Visibility mode specifies whether the features of the base class are privately derived or publicly derived.
  • 4. Types of Inheritance  Single Inheritance  Multiple Inheritance  Hierarchical Inheritance  Multilevel Inheritance  Hybrid Inheritance
  • 5. Single Inheritance  In single inheritance there exists single base class and single derived class.  It is the most simplest form of inheritance.
  • 6. Example of single inheritance
  • 8. Multiple inheritance  Multiple inheritance occurs when a class is inherit from more than one base class.  Derived class can inherit features from multiple base classes using multiple inheritance.
  • 9. Example of multiple inheritance
  • 11. Hierarchical inheritance In this type of inheritance, more than one sub class is inherited from a single base class. i.e. more than one derived class is created from a single base class.
  • 12. Example of hierarchical inheritance
  • 14. Multilevel inheritance In this type of inheritance, a derived class is created from another derived class. The class C serves as a base class for the derived class B, which in turn serves as a base class for the derived class A. The class B as intermediate base class since it provides a link for the inheritance between A and C the chain ABC is known as inheritance path. Class C {………}; //base class Class B: public C {………}; //B derived from C Class A: public B {……}; //A derived form B
  • 15. Example of Multilevel inheritance
  • 17. Hybrid inheritance Hybrid inheritance is implemented by combining more than one type of inheritance. For example: combining hierarchical inheritance and multiple inheritance.
  • 18. Example of Hybrid inheritance
  • 20. Virtual base class Consider a situation where three kind of inheritance, namely, multilevel, multiple and hierarchical inheritance, are involved. This is illustrated in the figure. The ‘child’ has two direct base classes ‘parent1’ and ‘Parent2’ which themselves have a common base class ‘grand parent’. The ‘child’ inherits the traits of ‘grandparent’ via two separate paths. It can also inherits the base class directly. The ‘grand parent’ is sometimes referred to as the indirect base class. This means ‘child’ is inherit the same property twice. To remove this duplication we declare the base class ‘grandparent’ as the virtual while declaring the direct or intermediate base class as shown:
  • 21. Syntax class A //grandparent { …….}; Class B1:virtual public A //parent1 {……..}; Class B2:public virtual A //parent2 {…….}; Class C:public B1,public B2 //child {…….}; //only one copy of A will be inherited
  • 22. Abstract classes An abstract class is one that is not used to create objects. An abstract class is designed only to act as a base class (to be inherited by other classes). It is a design concept in program development and provides a base upon which other classes may be built. The concept can be explained through a simple example of an abstract base class vehicle which may be declared in a program for deriving LMV (light motor vehicle),HMV (heavy motor vehicle) and TW(two wheeler) derived classes. A pure virtual function spec() may be set the specification of LMV as per its four wheel and smaller engine and that of HMV as per its eight or more wheels and relatively larger engine.
  • 23. Example Class vehicle //abstract base class { private: Datatype d1,d2; public: virtual void spec()=0; //pure virtual funtion }; Class LMV : public vehicle { public: void spec(){ ……. } //LMV definition of spec function };
  • 24. Example Class HMV : public vehicle { public: void spec(){ …….. } HMV definition of spec function }; Class TW : public vehicle { public: void spec(){ …….. } //TW definition of spec function };
  • 25. Advantages of inheritance  Inheritance promote reusability. When a class inherits or derives another class, it can access all functionality of inherited class.  Reusability enhanced reliability. the base class code is already tested and debugged.  Inheritance helps to reduce code redundancy and supports code extensibility.
  • 26. Disadvantages of inheritance  Inherited functions work slower than the normal function as there is indirection.  Improper use of inheritance lead to wrong solution.  Inheritance increases the coupling between base class and derived class. A change in base class will affects all the child classes.

Editor's Notes

  • #2: NOTE: To change the image on this slide, select the picture and delete it. Then click the Pictures icon in the placeholder to insert your own image.