SlideShare a Scribd company logo
Object-Oriented
Programming: Inheritance
Outline
โ€ข Introduction
โ€ข Protected members in inheritance
โ€ข Relationship between Base Classes and Derived Classes
โ€ข Benefits and Drawbacks of Inheritance
โ€ข Constructors and Destructors in Derived Classes
โ€ข Public, Protected and Private Inheritance
โ€ข Software Engineering with Inheritance
Introduction
โ€ข Inheritance is a core concept in object-oriented programming (OOP).
It allows a class to inherit properties and behaviors from another
class. This is a powerful way to reuse code and promote code
abstraction.
โ€ข Inheritance works by creating a subclass that inherits from a
superclass. The subclass inherits all of the attributes and methods of
the superclass, and it can also add its own attributes and methods.
โ€ข Parent โ€“ Child Relationship.
Types of inheritance
Here are some of the types of inheritance:
โ€ข Single inheritance: A subclass inherits from a single superclass.
โ€ข Multiple inheritance: A subclass inherits from multiple superclasses.
โ€ข Hierarchical inheritance: A class hierarchy is formed when a subclass
inherits from another subclass.
โ€ข Hybrid inheritance: A mix of two or more of the above types of
inheritance occurs.
Syntax
class Subclassโ€™Name : access_specifier BaseClassโ€™Name {
// members of subclass
};
The access_specifier can be one of the following:
โ€ข public: The subclass inherits all of the public members of the base
class.
โ€ข protected: The subclass inherits all of the protected members of the
base class.
โ€ข private: The subclass inherits none of the members of the base class.
Example
Animal class is Base Class/parent
class and Dog class is Derived
class/sub class.
Protected members in inheritance,oop,c++
In C++, protected members are members of a class that can only be
accessed by the class itself, its subclasses, and friends.
โ€ข Protected members are similar to private members, but they can be
inherited by subclasses. Private members are not accessible to
subclasses or friends.
โ€ข The syntax for declaring a protected member in C++ is:
class MyClass {
protected:
int x;
};
Relationship between Base Classes and
Derived Classes
In C++, a base class is a class from which other classes are derived. The
derived classes are called subclasses. The base class is the "parent" of the
subclasses, and the subclasses are the "children" of the base class.
The relationship between a base class and its subclasses is one of
inheritance. This means that the subclasses inherit all of the properties and
behaviors of the base class. The subclasses can then add their own properties and
behaviors, or they can override the properties and behaviors of the base class.
Benefits and Drawbacks of Inheritance
Here are some of the benefits of using inheritance in C++:
I. It allows us to reuse code.
II. It helps us to organize our code.
III. It can help us to make our code more robust and easier to
maintain.
Here are some of the drawbacks of using inheritance in C++:
I. It can make the code more complex.
II. It can make it difficult to track down the source of errors.
Constructors and Destructors in Derived Classes
When a subclass inherits from a base class, the subclass inherits the base class's constructors and
destructors. However, the subclass can also define its own constructors and destructors.
If the subclass defines its own constructors, the base class's constructors will be called
automatically when the subclass object is created.
The order in which the constructors are called is as follows:
โ€ข The base class's default constructor is called.
โ€ข The subclass's default constructor is called.
โ€ข If the subclass defines any parameterized constructors, they are called in the order that they are
defined.
If the subclass defines its own destructor, the base class's destructor will be called automatically
when the subclass object is destroyed. The order in which the destructors are called is as follows:
โ€ข The subclass's destructor is called.
โ€ข The base class's destructor is called.
Example
When a DerivedClass object is created,
the following happens:
โ€ข The BaseClass class's default constructor
is called.
โ€ข The DerivedClass class's default
constructor is
called.
When a DerivedClass object is destroyed,
the following happens:
โ€ข The DerivedClass class's destructor is
called.
โ€ข The BaseClass class's destructor is
called.
Public, Protected and Private Inheritance
โ€ข Public inheritance is the default type of inheritance in C++. When a class
inherits from another class in public mode, the subclass inherits all of the
public members of the base class. This means that the subclass can access
the public members of the base class as if they were its own members.
โ€ข Protected inheritance is a type of inheritance where the subclass inherits
all of the protected members of the base class. This means that the
subclass can access the protected members of the base class, but it cannot
access the public members of the base class.
โ€ข Private inheritance is a type of inheritance where the subclass inherits all
of the private members of the base class. This means that the subclass can
only access the private members of the base class through the base class's
methods.
Public, Protected and Private Inheritanceโ€ฆ..
Type of inheritance Access to base class members
Public inheritance Public and protected members
Protected inheritance Protected members
Private inheritance Private members
Software Engineering with Inheritance
โ€ข Inheritance is a powerful tool in software engineering that can be used to
improve the design and implementation of our code. It allows us to reuse code
that has already been written, and it can also help us to abstract away the details
of how something works.
Here are some of the ways that inheritance can be used in software engineering:
โ€ข To create a hierarchy of classes: Inheritance can be used to create a hierarchy of
classes, where each class inherits from a more general class. This can help to
organize our code and make it easier to understand.
โ€ข To implement polymorphism: Inheritance can be used to implement
polymorphism, which allows us to treat different objects in the same way. This
can make our code more flexible and easier to use.
โ€ข To reuse code: Inheritance can be used to reuse code that has already been
written. This can save us time and effort, and it can also help to keep our code
consistent.
End

More Related Content

Similar to Object oriented programming new syllabus presentation (20)

PDF
INHERITANCE
RohitK71
ย 
PPTX
inheritance
krishna partiwala
ย 
PPTX
Inheritance in c++ by Manan Pasricha
MananPasricha
ย 
PPT
6 Inheritance
Praveen M Jigajinni
ย 
PPT
Inheritance, Object Oriented Programming
Arslan Waseem
ย 
PPTX
inheritance_OOPC_datastream.ppttttttttttttttx
SanskritiGupta39
ย 
PPTX
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
ย 
PPTX
Introduction to Inheritance
Keshav Vaswani
ย 
PPTX
00ps inheritace using c++
sushamaGavarskar1
ย 
PPTX
EASY TO LEARN INHERITANCE IN C++
Nikunj Patel
ย 
PPTX
Inheritance in C++ (Programming Fundamentals)
Home
ย 
PPSX
Inheritance and Polymorphism in Oops
LalfakawmaKh
ย 
PPTX
Lecture 5.mte 407
rumanatasnim415
ย 
PPTX
Inheritance
Munsif Ullah
ย 
PPTX
C++ programming public, private inheritance
bilalisb999
ย 
PPTX
Inheritance
prashant prath
ย 
PPT
Inheritance
PriyankaAkhil
ย 
PPT
inheritance
Amir_Mukhtar
ย 
PPTX
Inheritance slides
awaisch888
ย 
PPTX
Inheritance in c++
Vineeta Garg
ย 
INHERITANCE
RohitK71
ย 
inheritance
krishna partiwala
ย 
Inheritance in c++ by Manan Pasricha
MananPasricha
ย 
6 Inheritance
Praveen M Jigajinni
ย 
Inheritance, Object Oriented Programming
Arslan Waseem
ย 
inheritance_OOPC_datastream.ppttttttttttttttx
SanskritiGupta39
ย 
inheriTANCE IN OBJECT ORIENTED PROGRAM.pptx
urvashipundir04
ย 
Introduction to Inheritance
Keshav Vaswani
ย 
00ps inheritace using c++
sushamaGavarskar1
ย 
EASY TO LEARN INHERITANCE IN C++
Nikunj Patel
ย 
Inheritance in C++ (Programming Fundamentals)
Home
ย 
Inheritance and Polymorphism in Oops
LalfakawmaKh
ย 
Lecture 5.mte 407
rumanatasnim415
ย 
Inheritance
Munsif Ullah
ย 
C++ programming public, private inheritance
bilalisb999
ย 
Inheritance
prashant prath
ย 
Inheritance
PriyankaAkhil
ย 
inheritance
Amir_Mukhtar
ย 
Inheritance slides
awaisch888
ย 
Inheritance in c++
Vineeta Garg
ย 

Recently uploaded (20)

PDF
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
ย 
PDF
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
ย 
PDF
Dipole Tech Innovations โ€“ Global IT Solutions for Business Growth
dipoletechi3
ย 
PDF
์œ ๋‹ˆํ‹ฐ์—์„œ Burst Compiler+ThreadedJobs+SIMD ์ ์šฉ์‚ฌ๋ก€
Seongdae Kim
ย 
PPTX
Agentic Automation Journey Series Day 2 โ€“ Prompt Engineering for UiPath Agents
klpathrudu
ย 
PDF
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
ย 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
ย 
PPTX
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
ย 
PDF
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
ย 
PDF
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
ย 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
ย 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
ย 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
ย 
PPTX
Home Care Tools: Benefits, features and more
Third Rock Techkno
ย 
PPTX
AEM User Group: India Chapter Kickoff Meeting
jennaf3
ย 
PDF
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
ย 
PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
ย 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
ย 
PDF
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
ย 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
ย 
Empower Your Tech Vision- Why Businesses Prefer to Hire Remote Developers fro...
logixshapers59
ย 
ERP Consulting Services and Solutions by Contetra Pvt Ltd
jayjani123
ย 
Dipole Tech Innovations โ€“ Global IT Solutions for Business Growth
dipoletechi3
ย 
์œ ๋‹ˆํ‹ฐ์—์„œ Burst Compiler+ThreadedJobs+SIMD ์ ์šฉ์‚ฌ๋ก€
Seongdae Kim
ย 
Agentic Automation Journey Series Day 2 โ€“ Prompt Engineering for UiPath Agents
klpathrudu
ย 
NEW-Viral>Wondershare Filmora 14.5.18.12900 Crack Free
sherryg1122g
ย 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
ย 
Build a Custom Agent for Agentic Testing.pptx
klpathrudu
ย 
AOMEI Partition Assistant Crack 10.8.2 + WinPE Free Downlaod New Version 2025
bashirkhan333g
ย 
Generic or Specific? Making sensible software design decisions
Bert Jan Schrijver
ย 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
ย 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
ย 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
ย 
Home Care Tools: Benefits, features and more
Third Rock Techkno
ย 
AEM User Group: India Chapter Kickoff Meeting
jennaf3
ย 
AI + DevOps = Smart Automation with devseccops.ai.pdf
Devseccops.ai
ย 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
ย 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
ย 
IDM Crack with Internet Download Manager 6.42 Build 43 with Patch Latest 2025
bashirkhan333g
ย 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
ย 
Ad

Object oriented programming new syllabus presentation

  • 2. Outline โ€ข Introduction โ€ข Protected members in inheritance โ€ข Relationship between Base Classes and Derived Classes โ€ข Benefits and Drawbacks of Inheritance โ€ข Constructors and Destructors in Derived Classes โ€ข Public, Protected and Private Inheritance โ€ข Software Engineering with Inheritance
  • 3. Introduction โ€ข Inheritance is a core concept in object-oriented programming (OOP). It allows a class to inherit properties and behaviors from another class. This is a powerful way to reuse code and promote code abstraction. โ€ข Inheritance works by creating a subclass that inherits from a superclass. The subclass inherits all of the attributes and methods of the superclass, and it can also add its own attributes and methods. โ€ข Parent โ€“ Child Relationship.
  • 4. Types of inheritance Here are some of the types of inheritance: โ€ข Single inheritance: A subclass inherits from a single superclass. โ€ข Multiple inheritance: A subclass inherits from multiple superclasses. โ€ข Hierarchical inheritance: A class hierarchy is formed when a subclass inherits from another subclass. โ€ข Hybrid inheritance: A mix of two or more of the above types of inheritance occurs.
  • 5. Syntax class Subclassโ€™Name : access_specifier BaseClassโ€™Name { // members of subclass }; The access_specifier can be one of the following: โ€ข public: The subclass inherits all of the public members of the base class. โ€ข protected: The subclass inherits all of the protected members of the base class. โ€ข private: The subclass inherits none of the members of the base class.
  • 6. Example Animal class is Base Class/parent class and Dog class is Derived class/sub class.
  • 7. Protected members in inheritance,oop,c++ In C++, protected members are members of a class that can only be accessed by the class itself, its subclasses, and friends. โ€ข Protected members are similar to private members, but they can be inherited by subclasses. Private members are not accessible to subclasses or friends. โ€ข The syntax for declaring a protected member in C++ is: class MyClass { protected: int x; };
  • 8. Relationship between Base Classes and Derived Classes In C++, a base class is a class from which other classes are derived. The derived classes are called subclasses. The base class is the "parent" of the subclasses, and the subclasses are the "children" of the base class. The relationship between a base class and its subclasses is one of inheritance. This means that the subclasses inherit all of the properties and behaviors of the base class. The subclasses can then add their own properties and behaviors, or they can override the properties and behaviors of the base class.
  • 9. Benefits and Drawbacks of Inheritance Here are some of the benefits of using inheritance in C++: I. It allows us to reuse code. II. It helps us to organize our code. III. It can help us to make our code more robust and easier to maintain. Here are some of the drawbacks of using inheritance in C++: I. It can make the code more complex. II. It can make it difficult to track down the source of errors.
  • 10. Constructors and Destructors in Derived Classes When a subclass inherits from a base class, the subclass inherits the base class's constructors and destructors. However, the subclass can also define its own constructors and destructors. If the subclass defines its own constructors, the base class's constructors will be called automatically when the subclass object is created. The order in which the constructors are called is as follows: โ€ข The base class's default constructor is called. โ€ข The subclass's default constructor is called. โ€ข If the subclass defines any parameterized constructors, they are called in the order that they are defined. If the subclass defines its own destructor, the base class's destructor will be called automatically when the subclass object is destroyed. The order in which the destructors are called is as follows: โ€ข The subclass's destructor is called. โ€ข The base class's destructor is called.
  • 11. Example When a DerivedClass object is created, the following happens: โ€ข The BaseClass class's default constructor is called. โ€ข The DerivedClass class's default constructor is called. When a DerivedClass object is destroyed, the following happens: โ€ข The DerivedClass class's destructor is called. โ€ข The BaseClass class's destructor is called.
  • 12. Public, Protected and Private Inheritance โ€ข Public inheritance is the default type of inheritance in C++. When a class inherits from another class in public mode, the subclass inherits all of the public members of the base class. This means that the subclass can access the public members of the base class as if they were its own members. โ€ข Protected inheritance is a type of inheritance where the subclass inherits all of the protected members of the base class. This means that the subclass can access the protected members of the base class, but it cannot access the public members of the base class. โ€ข Private inheritance is a type of inheritance where the subclass inherits all of the private members of the base class. This means that the subclass can only access the private members of the base class through the base class's methods.
  • 13. Public, Protected and Private Inheritanceโ€ฆ.. Type of inheritance Access to base class members Public inheritance Public and protected members Protected inheritance Protected members Private inheritance Private members
  • 14. Software Engineering with Inheritance โ€ข Inheritance is a powerful tool in software engineering that can be used to improve the design and implementation of our code. It allows us to reuse code that has already been written, and it can also help us to abstract away the details of how something works. Here are some of the ways that inheritance can be used in software engineering: โ€ข To create a hierarchy of classes: Inheritance can be used to create a hierarchy of classes, where each class inherits from a more general class. This can help to organize our code and make it easier to understand. โ€ข To implement polymorphism: Inheritance can be used to implement polymorphism, which allows us to treat different objects in the same way. This can make our code more flexible and easier to use. โ€ข To reuse code: Inheritance can be used to reuse code that has already been written. This can save us time and effort, and it can also help to keep our code consistent.
  • 15. End