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)

PPTX
Object oriented programming
Saiful Islam Sany
 
PPTX
full defination of final opp.pptx
rayanbabur
 
PPT
Overview of Object Oriented Programming using C++
jayanthi699330
 
PPTX
Class and Objects in python programming.pptx
Rajtherock
 
PPTX
Introduction to OOP concepts
Ahmed Farag
 
PPTX
INHERITANCES.pptx
VISHNU PRIYA NR
 
PPT
Inheritance, Object Oriented Programming
Arslan Waseem
 
PPTX
Oopsinphp
NithyaNithyav
 
PPTX
java part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
PPT
10.Inheritance.ppt for oops programinggg
sanketkashyap2023
 
PPTX
Inheritance
sourav verma
 
PPTX
C# structure
ElangovanTechNotesET
 
PPT
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
akashsachu221
 
PPTX
asic computer is an electronic device that can receive, store, process, and o...
vaishalisharma125399
 
PPTX
Object Oriented Programming Tutorial.pptx
ethiouniverse
 
PPTX
Object Oriented Programming
RatnaJava
 
PPT
Topic inheritance
Ankit Kumar
 
PPT
Inheritance in C++
Shweta Shah
 
PPTX
27csharp
Sireesh K
 
PPTX
27c
Sireesh K
 
Object oriented programming
Saiful Islam Sany
 
full defination of final opp.pptx
rayanbabur
 
Overview of Object Oriented Programming using C++
jayanthi699330
 
Class and Objects in python programming.pptx
Rajtherock
 
Introduction to OOP concepts
Ahmed Farag
 
INHERITANCES.pptx
VISHNU PRIYA NR
 
Inheritance, Object Oriented Programming
Arslan Waseem
 
Oopsinphp
NithyaNithyav
 
java part 1 computer science.pptx
MUHAMMED MASHAHIL PUKKUNNUMMAL
 
10.Inheritance.ppt for oops programinggg
sanketkashyap2023
 
Inheritance
sourav verma
 
C# structure
ElangovanTechNotesET
 
Java Fundamentalojhgghjjjjhhgghhjjjjhhj.ppt
akashsachu221
 
asic computer is an electronic device that can receive, store, process, and o...
vaishalisharma125399
 
Object Oriented Programming Tutorial.pptx
ethiouniverse
 
Object Oriented Programming
RatnaJava
 
Topic inheritance
Ankit Kumar
 
Inheritance in C++
Shweta Shah
 
27csharp
Sireesh K
 
27c
Sireesh K
 

Recently uploaded (20)

PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
PDF
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PDF
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
PPTX
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
PPTX
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
PDF
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Migrating Millions of Users with Debezium, Apache Kafka, and an Acyclic Synch...
MD Sayem Ahmed
 
SciPy 2025 - Packaging a Scientific Python Project
Henry Schreiner
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
Agentic Automation Journey Session 1/5: Context Grounding and Autopilot for E...
klpathrudu
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
The 5 Reasons for IT Maintenance - Arna Softech
Arna Softech
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
HiHelloHR – Simplify HR Operations for Modern Workplaces
HiHelloHR
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pptx
Varsha Nayak
 
Agentic Automation: Build & Deploy Your First UiPath Agent
klpathrudu
 
[Solution] Why Choose the VeryPDF DRM Protector Custom-Built Solution for You...
Lingwen1998
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
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