SlideShare ist ein Scribd-Unternehmen logo
1 von 13
Welcome,
Let’s gear up for the basics of Inheritance and
elements of its architecture.
Agenda of the presentation

‱     Basics of inheritance

‱     Private v/s public inheritance

‱     Glimpse at an example
Inheritance




In Object Oriented Programming, Inheritance is the process by which objects of
one class acquire the properties and functionality of objects of another class.

It supports the concept of hierarchical classification.
Example at a glance



                                      Parent Class




                      Child Classes
What in the need of inheritance in c++?


One reason to use inheritance is that it allows you to reuse code from a previous
project but gives you the flexibility to slightly modify it if the old code doesn’t do
exactly what you need for the new project.

It doesn’t make sense to start every new project from scratch since some code will
certainly be repeated in several programs and you should strive to build on what you did
previously.


Moreover, it is easy to make an error if we try to modify the original class, but we are
less likely to make an error if we leave the original alone and only add to it.


 Another reason for using inheritance is if the project requires the use of several classes
 which are very similar but slightly different.
What is a class?
A class is an expanded concept of a data structure: instead of holding only data, it
can hold both data and functions.

Base Class
A base class is a class that is created with the intention of deriving other
classes from it.

Parent Class
A parent class is the closest class that we derived from to create the one we are referencing
as the child class.

Child Class
A child class is a class that was derived from another, that will now be the parent class to it.
Example of a Parent Class


As an example, suppose you are creating a game, something using different cars,
and you need specific type of car for the policemen and another type for the
player(s). Both car types share similar properties. The major difference (on this
example case) would be that the policemen type would have sirens on
top of their cars and the players' cars will not.
What is a private class?

Private members of a class are accessible only from within other members of the
same class or from their friends.

What is a protected class?

Protected members are accessible from members of their same class and from
their friends, but also from members of their derived classes.

What is a public class?

Finally, public members are accessible from anywhere the object is visible.
This is our base class or parent class whatever you prefer


Class A
{

public:
  int apub;
private:
  int aprv; // this won't be accessible to child/sub classes
protected:
  int apro;

}


Basic thumb rule in inheritance. You cannot inherit private members.
Public visibility mode during Inheritance

Public inheritance will inherit protected variables & functions.

Class B : public A // this is inheritance with private specifier
{
          public:
          int bpub; // also has access to aprv
          private:
          int bprv; // no access to apub
          protected:
          int bpro; // also has access to apro
}


here in class B you can use apub, bpub, apro, bpro but you cannot
access aprv because aprv is private variable of class A.
Private visibility mode during Inheritance

private members of class are are not accessible but protected & public will
become private members of class B

So anything that is public or protected in Class A will become private in class
B

Class B : private A // this is inheritance with private specifier
{

public:
int bpub;

private:
int bprv; // also has access to apub,apro but now apub and apro are private
memebers of this class

protected:
int bpro;

}
Protected visibility mode during Inheritance

protected inheritance will inherit protected as well as public variables
& methods of base class (class A) with visibilty modifier as protected

Class B : protected A
{

public:
int bpub;

private:
int bpri

protected:
int bpro; // also has access to apub,apro

}
Feel free to ask if there are any questions or queries




                   Thank you




                                  Prepared by : Pooja K. Doshi

Weitere Àhnliche Inhalte

Was ist angesagt?

Paca oops slid
Paca oops slidPaca oops slid
Paca oops slid
pacatarpit
 

Was ist angesagt? (11)

Inheritance in c++ by Manan Pasricha
Inheritance in c++ by Manan PasrichaInheritance in c++ by Manan Pasricha
Inheritance in c++ by Manan Pasricha
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1
 
Multi image object detection v5
Multi image object detection v5Multi image object detection v5
Multi image object detection v5
 
Structure of java program diff c- cpp and java
Structure of java program  diff c- cpp and javaStructure of java program  diff c- cpp and java
Structure of java program diff c- cpp and java
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Java
 
SD & D Implementation
SD & D ImplementationSD & D Implementation
SD & D Implementation
 
Intro tooop
Intro tooopIntro tooop
Intro tooop
 
How do i use inheritance in java?
How do i use inheritance in java?How do i use inheritance in java?
How do i use inheritance in java?
 
Paca oops slid
Paca oops slidPaca oops slid
Paca oops slid
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+java
 
Programming Paradigms
Programming ParadigmsProgramming Paradigms
Programming Paradigms
 

Andere mochten auch

Andere mochten auch (9)

Basic Themes of Al-Quran
Basic Themes of Al-QuranBasic Themes of Al-Quran
Basic Themes of Al-Quran
 
Up recruitment
Up recruitmentUp recruitment
Up recruitment
 
Power Point Skills
Power Point  SkillsPower Point  Skills
Power Point Skills
 
Management of nursing service
Management of nursing serviceManagement of nursing service
Management of nursing service
 
Strategic plan
Strategic plan Strategic plan
Strategic plan
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentation
 
17 Ways to Design a Presentation People Want to View
17 Ways to Design a Presentation People Want to View17 Ways to Design a Presentation People Want to View
17 Ways to Design a Presentation People Want to View
 
Mobile-First SEO - The Marketers Edition #3XEDigital
Mobile-First SEO - The Marketers Edition #3XEDigitalMobile-First SEO - The Marketers Edition #3XEDigital
Mobile-First SEO - The Marketers Edition #3XEDigital
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI Explainer
 

Ähnlich wie Inheritance

Net Interview-Questions 1 - 16.pdf
Net Interview-Questions 1 - 16.pdfNet Interview-Questions 1 - 16.pdf
Net Interview-Questions 1 - 16.pdf
PavanNarne1
 

Ähnlich wie Inheritance (20)

Java OOPS Concept
Java OOPS ConceptJava OOPS Concept
Java OOPS Concept
 
Ganesh groups
Ganesh groupsGanesh groups
Ganesh groups
 
Inheritance
InheritanceInheritance
Inheritance
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 
Net Interview-Questions 1 - 16.pdf
Net Interview-Questions 1 - 16.pdfNet Interview-Questions 1 - 16.pdf
Net Interview-Questions 1 - 16.pdf
 
Inheritance
Inheritance Inheritance
Inheritance
 
Java_notes.ppt
Java_notes.pptJava_notes.ppt
Java_notes.ppt
 
Lecture 12
Lecture 12Lecture 12
Lecture 12
 
Inheritance
InheritanceInheritance
Inheritance
 
Opp concept in c++
Opp concept in c++Opp concept in c++
Opp concept in c++
 
00ps inheritace using c++
00ps inheritace using c++00ps inheritace using c++
00ps inheritace using c++
 
Inheritance
InheritanceInheritance
Inheritance
 
OOP interview questions & answers.
OOP interview questions & answers.OOP interview questions & answers.
OOP interview questions & answers.
 
Inheritance in OOPs with java
Inheritance in OOPs with javaInheritance in OOPs with java
Inheritance in OOPs with java
 
Introduction to object oriented programming concepts
Introduction to object oriented programming conceptsIntroduction to object oriented programming concepts
Introduction to object oriented programming concepts
 
OOP in Java Presentation.pptx
OOP in Java Presentation.pptxOOP in Java Presentation.pptx
OOP in Java Presentation.pptx
 
Object oreinted php | OOPs
Object oreinted php | OOPsObject oreinted php | OOPs
Object oreinted php | OOPs
 
4th_class.pdf
4th_class.pdf4th_class.pdf
4th_class.pdf
 
oop.pptx
oop.pptxoop.pptx
oop.pptx
 
11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 

KĂŒrzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

KĂŒrzlich hochgeladen (20)

MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls đŸ„° 8617370543 Service Offer VIP Hot Model
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Inheritance

  • 1. Welcome, Let’s gear up for the basics of Inheritance and elements of its architecture.
  • 2. Agenda of the presentation ‱ Basics of inheritance ‱ Private v/s public inheritance ‱ Glimpse at an example
  • 3. Inheritance In Object Oriented Programming, Inheritance is the process by which objects of one class acquire the properties and functionality of objects of another class. It supports the concept of hierarchical classification.
  • 4. Example at a glance Parent Class Child Classes
  • 5. What in the need of inheritance in c++? One reason to use inheritance is that it allows you to reuse code from a previous project but gives you the flexibility to slightly modify it if the old code doesn’t do exactly what you need for the new project. It doesn’t make sense to start every new project from scratch since some code will certainly be repeated in several programs and you should strive to build on what you did previously. Moreover, it is easy to make an error if we try to modify the original class, but we are less likely to make an error if we leave the original alone and only add to it. Another reason for using inheritance is if the project requires the use of several classes which are very similar but slightly different.
  • 6. What is a class? A class is an expanded concept of a data structure: instead of holding only data, it can hold both data and functions. Base Class A base class is a class that is created with the intention of deriving other classes from it. Parent Class A parent class is the closest class that we derived from to create the one we are referencing as the child class. Child Class A child class is a class that was derived from another, that will now be the parent class to it.
  • 7. Example of a Parent Class As an example, suppose you are creating a game, something using different cars, and you need specific type of car for the policemen and another type for the player(s). Both car types share similar properties. The major difference (on this example case) would be that the policemen type would have sirens on top of their cars and the players' cars will not.
  • 8. What is a private class? Private members of a class are accessible only from within other members of the same class or from their friends. What is a protected class? Protected members are accessible from members of their same class and from their friends, but also from members of their derived classes. What is a public class? Finally, public members are accessible from anywhere the object is visible.
  • 9. This is our base class or parent class whatever you prefer Class A { public: int apub; private: int aprv; // this won't be accessible to child/sub classes protected: int apro; } Basic thumb rule in inheritance. You cannot inherit private members.
  • 10. Public visibility mode during Inheritance Public inheritance will inherit protected variables & functions. Class B : public A // this is inheritance with private specifier { public: int bpub; // also has access to aprv private: int bprv; // no access to apub protected: int bpro; // also has access to apro } here in class B you can use apub, bpub, apro, bpro but you cannot access aprv because aprv is private variable of class A.
  • 11. Private visibility mode during Inheritance private members of class are are not accessible but protected & public will become private members of class B So anything that is public or protected in Class A will become private in class B Class B : private A // this is inheritance with private specifier { public: int bpub; private: int bprv; // also has access to apub,apro but now apub and apro are private memebers of this class protected: int bpro; }
  • 12. Protected visibility mode during Inheritance protected inheritance will inherit protected as well as public variables & methods of base class (class A) with visibilty modifier as protected Class B : protected A { public: int bpub; private: int bpri protected: int bpro; // also has access to apub,apro }
  • 13. Feel free to ask if there are any questions or queries Thank you Prepared by : Pooja K. Doshi