SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

Inheritance in c++ by Manan Pasricha
Inheritance in c++ by Manan PasrichaInheritance in c++ by Manan Pasricha
Inheritance in c++ by Manan PasrichaMananPasricha
 
The Go Programing Language 1
The Go Programing Language 1The Go Programing Language 1
The Go Programing Language 1İbrahim Kürce
 
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 javaMadishetty Prathibha
 
Practical OOP In Java
Practical OOP In JavaPractical OOP In Java
Practical OOP In Javawiradikusuma
 
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?kritikumar16
 
Paca oops slid
Paca oops slidPaca oops slid
Paca oops slidpacatarpit
 
Object+oriented+programming+in+java
Object+oriented+programming+in+javaObject+oriented+programming+in+java
Object+oriented+programming+in+javaYe Win
 
Programming Paradigms
Programming ParadigmsProgramming Paradigms
Programming ParadigmsDirecti Group
 

Mais procurados (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
 

Destaque

Power Point Skills
Power Point  SkillsPower Point  Skills
Power Point SkillsPC 4 All
 
Management of nursing service
Management of nursing serviceManagement of nursing service
Management of nursing servicejensensam
 
Strategic plan
Strategic plan Strategic plan
Strategic plan Wael Ammar
 
Slideshare Powerpoint presentation
Slideshare Powerpoint presentationSlideshare Powerpoint presentation
Slideshare Powerpoint presentationelliehood
 
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 ViewJim MacLeod
 
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 #3XEDigitalAleyda Solís
 
Hype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerHype vs. Reality: The AI Explainer
Hype vs. Reality: The AI ExplainerLuminary Labs
 

Destaque (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
 

Semelhante a Inheritance

Semelhante a 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
 

Último

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
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 connectorsNanddeep Nachan
 
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 2024The Digital Insurer
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
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, ...apidays
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businesspanagenda
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
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
 
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
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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, ...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 

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