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)

PDF
OOP Assign No.03(AP).pdf
PPTX
inheritance in OOPM
PPTX
Inheritance
PPT
Inheritance.ppt
PPTX
Inheritance
PPTX
Oopc (group 9)
PPTX
INHERITANCES.pptx
PDF
PPTX
Inheritance
PPTX
Inheritance.pptx
PPTX
Inheritance
PPSX
Inheritance and Polymorphism in Oops
PPTX
Inheritance in C++
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
PPTX
Inheritance (with classifications)
PDF
Inheritance
PPT
Topic inheritance
PPTX
Inheritance
PPTX
PPT
session 24_Inheritance.ppt
OOP Assign No.03(AP).pdf
inheritance in OOPM
Inheritance
Inheritance.ppt
Inheritance
Oopc (group 9)
INHERITANCES.pptx
Inheritance
Inheritance.pptx
Inheritance
Inheritance and Polymorphism in Oops
Inheritance in C++
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
Inheritance (with classifications)
Inheritance
Topic inheritance
Inheritance
session 24_Inheritance.ppt
Ad

Recently uploaded (20)

PPTX
web development for engineering and engineering
PPTX
UNIT 4 Total Quality Management .pptx
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
CH1 Production IntroductoryConcepts.pptx
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPT
Mechanical Engineering MATERIALS Selection
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PPTX
additive manufacturing of ss316l using mig welding
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPTX
Sustainable Sites - Green Building Construction
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Welding lecture in detail for understanding
web development for engineering and engineering
UNIT 4 Total Quality Management .pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
CH1 Production IntroductoryConcepts.pptx
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Structs to JSON How Go Powers REST APIs.pdf
Mechanical Engineering MATERIALS Selection
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
additive manufacturing of ss316l using mig welding
Lesson 3_Tessellation.pptx finite Mathematics
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Sustainable Sites - Green Building Construction
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
OOP with Java - Java Introduction (Basics)
Welding lecture in detail for understanding

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.