SlideShare uma empresa Scribd logo
1 de 25
   The OO principle of inheritance enables you
    to create a generalized class and then derive
    more specialized classes from it.
   Inheritance is the ability to take on the
    characteristics of the class or derived class on
    which it is based.
   Specifies an “is-a” kind of relationship
Person



      Employee     Student



Full-time   Part-time
Employee    Employee
Shape



Rectangle         Circle



 Square
   New classes that we create from the existing
    class are called derived classes; the existing
    classes are called base classes.
class className:memberAccessSpecifier baseClassName
{
   memberList;

};
    Where:
      memberAccessSpecifier – is public, private, or protected. When no
       memberAccessSpecifier is specified, it is assumed to be a private
       inheritance.
class Circle : public Shape
{
   .
   .
   .
};
class Circle : private Shape
{
   .
   .
   .
};
1.   The private members of a base class are
     private to the base class; hence the
     members of the derived class cannot
     directly access them. In other words, when
     you write the definitions of the member
     functions of the derived class, you cannot
     directly access the private members of the
     base class.
2.   The public members of a base class can be
     inherited either as public members or as
     private members by the derived class. That
     is, the public members of the base class can
     become either public or private members of
     the derived class.
3.   The derived class can include additional
     members – data and/or functions.
4.   The derived class can redefine the public
     member functions of the base class. That is,
     in the derived class, you can have a member
     function with the same name, number and
     types of parameters as function in the base
     class. However, this redefinition applies
     only to the object of the derived class, not to
     the objects of the base class.
5.   All member variables of the base class are
     also member variables of the derived class.
     Similarly, the member functions of the base
     class(unless redefined) are also member
     functions of the derived class. (Remember
     Rule 1 when accessing a member of the base
     class in the derived class.
class Derived:Base           class Base
{                            {
   int y;                       int x;
   public :                     public :
       void print() const;      void print()const;
};                           };
void Derived::print()const   void Base::print()const
{                            {
   cout<<y<<endl;               cout<<x<<endl;
}                            }
   To redefine a public member function of a
    base class in the derived class, the
    corresponding function in the derived class
    must have the same name, number, and
    types of parameters.
class RectangleType
{
   public:
       void setDimension(double, double);
       double getLength()const;
       double getWidth() const;
       double area()const;
       double perimeter()const;
       void print()const;
       RectangleType();
       RectangleType(double, double);
   private:
       double length;
       double width;
};
#include "RectangleType.h"         double RectangleType::getLength
#include<iostream>                   ()const
using namespace std;               {
                                     return length;
void RectangleType::setDimension   }
   (double l, double w)            double RectangleType::getWidth
{                                    ()const
   if (l>=0)                       {
         length = l;                 return width;
   else                            }
         length =0;
    if (w>=0)
         width = w;
    else
         width = 0;
}
double RectangleType::area()const   RectangleType::RectangleType(double l,
{                                      double w)
   return length * width;           {
}                                      setDimension(l,w);
double RectangleType::perimeter     }
   ()const                          RectangleType::RectangleType()
{                                   {
   return 2*(length + width);          length =0;
}                                      width =0;
void RectangleType::print() const   }
{
   cout<<"Length = "<<length
        <<"Width = " <<width;
}
 Define a class named BoxType
 BoxType contains data members that stores the length,
  width and height of a box.
 It has the following member functions :
     Function that sets the dimension of the box
     Function that sets a value for each data member of the class
     Function that returns the value of each data member of the
        class
       Function that prints the values of the data members of the class
       Function that computes and returns the area of the box
       Function that computes and returns the volume of the box
       Default constructor which initializes data members to 0
       Parameterized constructor which initializes data member to a
        value set by the object of the class
   In general, while writing the definitions of the
    member functions of a derived class to
    specify a call to a public member function of
    the base class we do the following:
     If the derived class overrides a public member
     function of the base class, then to specify a call to
     that public member function of the base class use
     the name of the base class followed by the scope
     resolution operator, ::, followed by the function
     name with the appropriate parameter list.
 If the derived class does not override a public
 member function of the base class, you may
 specify a call to that public member function by
 using the name of the function and the
 appropriate parameter list.
   Recall:
     private members of a class are private to the class and
      cannot be directly accessed outside the class. Only
      member functions of that class can access the private
      members.
     If public, anyone can access that member
     So for a base class to give access to a member to its
      derived class and still prevent its direct access outside the
      class, you must declare the member under the
      memberAccessSpecifier protected.
      ▪ The accessibility of a protected class is between public and private
      ▪ A derived class can directly access the protected members of the base
        class.
   Example:
    class B : memberAccessSpecifier A
    {
       :
       :
    };
   memberAccessSpecifier is either private, public
    or protected
   If memberAccessSpecifier is public – that is
    inheritance is public - then:
     The public members of A are public members of
      B. They can be directly accessed in class B.
     The protected members of A re protected
      members of B. They can be directly accessed by
      the member functions of B.
     The private members of A are hidden in B. They
      can be accessed by the member functions of B
      through the public and protected members of A.
   If memberAccessSpecifier is protected– that is
    inheritance is protected - then:
     The public members of A are protected members of B.
      They can be accessed by the member functions of B.
     The protected members of A are protected members
      of B. They can be accessed by the member functions
      of B.
     The private members of A are hidden in B. They can
      be accessed by the member functions of B through
      the private or protected members of A.
   If memberAccessSpecifier is private– that is
    inheritance is private - then:
     The public members of A are private members of B.
      They can be accessed by the member functions of B.
     The protected members of A are private members of
      B. They can be accessed by the member functions of
      B.
     The private members of A are hidden in B. They can
      be accessed by the member functions of B through
      the private or protected members of A.

Mais conteúdo relacionado

Mais procurados

Friend functions
Friend functions Friend functions
Friend functions Megha Singh
 
Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-classDeepak Singh
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.MASQ Technologies
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesSunil Kumar Gunasekaran
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classesFajar Baskoro
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classesasadsardar
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++NainaKhan28
 
Seminar on java
Seminar on javaSeminar on java
Seminar on javashathika
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsEng Teong Cheah
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasShahzad Younas
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingSyed Faizan Hassan
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)Ritika Sharma
 

Mais procurados (20)

Friend functions
Friend functions Friend functions
Friend functions
 
Inheritance
InheritanceInheritance
Inheritance
 
Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-class
 
Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.Inheritance OOP Concept in C++.
Inheritance OOP Concept in C++.
 
Class and object in C++ By Pawan Thakur
Class and object in C++ By Pawan ThakurClass and object in C++ By Pawan Thakur
Class and object in C++ By Pawan Thakur
 
JAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examplesJAVA Notes - All major concepts covered with examples
JAVA Notes - All major concepts covered with examples
 
Inheritance
InheritanceInheritance
Inheritance
 
Lect 1-java object-classes
Lect 1-java object-classesLect 1-java object-classes
Lect 1-java object-classes
 
inheritance c++
inheritance c++inheritance c++
inheritance c++
 
Friends function and_classes
Friends function and_classesFriends function and_classes
Friends function and_classes
 
Encapsulation
EncapsulationEncapsulation
Encapsulation
 
Class and object in c++
Class and object in c++Class and object in c++
Class and object in c++
 
Seminar on java
Seminar on javaSeminar on java
Seminar on java
 
Inheritance
InheritanceInheritance
Inheritance
 
Learn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & MethodsLearn C# Programming - Encapsulation & Methods
Learn C# Programming - Encapsulation & Methods
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
CLASS & OBJECT IN JAVA
CLASS & OBJECT  IN JAVACLASS & OBJECT  IN JAVA
CLASS & OBJECT IN JAVA
 
inheritance in C++
inheritance in C++inheritance in C++
inheritance in C++
 
How to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programmingHow to write you first class in c++ object oriented programming
How to write you first class in c++ object oriented programming
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 

Destaque

บุคลากรครูที่เกษียณ
บุคลากรครูที่เกษียณบุคลากรครูที่เกษียณ
บุคลากรครูที่เกษียณCalvinlok
 
Nº84 national geographic historia
Nº84 national geographic historiaNº84 national geographic historia
Nº84 national geographic historialectora50
 
Pearson Career Workforce Education
Pearson Career Workforce EducationPearson Career Workforce Education
Pearson Career Workforce Educationpearsoncareer
 
Socialmedia2.0
Socialmedia2.0Socialmedia2.0
Socialmedia2.0aphukong
 
APARTMENT IN WARSAW
APARTMENT IN WARSAWAPARTMENT IN WARSAW
APARTMENT IN WARSAWTrzySiostry
 
บุคลากรครูที่เกษียณ12
บุคลากรครูที่เกษียณ12บุคลากรครูที่เกษียณ12
บุคลากรครูที่เกษียณ12Calvinlok
 
FM&amp;P 2011 - Diageo
FM&amp;P 2011 - DiageoFM&amp;P 2011 - Diageo
FM&amp;P 2011 - Diageojasonawatar
 
Aa Sponsor11 Proposal Jamaica
Aa  Sponsor11  Proposal  JamaicaAa  Sponsor11  Proposal  Jamaica
Aa Sponsor11 Proposal JamaicaDerek Krow
 
ท่องเที่ยวเชิงประวัติศาสตร์
ท่องเที่ยวเชิงประวัติศาสตร์ท่องเที่ยวเชิงประวัติศาสตร์
ท่องเที่ยวเชิงประวัติศาสตร์Calvinlok
 
20070901.mydomain
20070901.mydomain20070901.mydomain
20070901.mydomainKen SASAKI
 
Meals on Wheels
Meals on WheelsMeals on Wheels
Meals on Wheelsbeajx3
 
Cja 463 policy development paper
Cja 463 policy development paperCja 463 policy development paper
Cja 463 policy development paperMelissaDonlon
 
Federal Legislative and Regulatory Update
Federal Legislative and Regulatory UpdateFederal Legislative and Regulatory Update
Federal Legislative and Regulatory Updatepearsoncareer
 
Media Placement Portfolio Lindsay Krupa
Media Placement Portfolio  Lindsay KrupaMedia Placement Portfolio  Lindsay Krupa
Media Placement Portfolio Lindsay KrupaLindsay Krupa
 
Actividades quandary
Actividades quandaryActividades quandary
Actividades quandaryJorge Vila
 
บุคลากรครูที่เกษียณ12
บุคลากรครูที่เกษียณ12บุคลากรครูที่เกษียณ12
บุคลากรครูที่เกษียณ12Calvinlok
 

Destaque (20)

บุคลากรครูที่เกษียณ
บุคลากรครูที่เกษียณบุคลากรครูที่เกษียณ
บุคลากรครูที่เกษียณ
 
My sister´s keeper
My sister´s keeperMy sister´s keeper
My sister´s keeper
 
Nº84 national geographic historia
Nº84 national geographic historiaNº84 national geographic historia
Nº84 national geographic historia
 
Pearson Career Workforce Education
Pearson Career Workforce EducationPearson Career Workforce Education
Pearson Career Workforce Education
 
Socialmedia2.0
Socialmedia2.0Socialmedia2.0
Socialmedia2.0
 
APARTMENT IN WARSAW
APARTMENT IN WARSAWAPARTMENT IN WARSAW
APARTMENT IN WARSAW
 
บุคลากรครูที่เกษียณ12
บุคลากรครูที่เกษียณ12บุคลากรครูที่เกษียณ12
บุคลากรครูที่เกษียณ12
 
FM&amp;P 2011 - Diageo
FM&amp;P 2011 - DiageoFM&amp;P 2011 - Diageo
FM&amp;P 2011 - Diageo
 
Aa Sponsor11 Proposal Jamaica
Aa  Sponsor11  Proposal  JamaicaAa  Sponsor11  Proposal  Jamaica
Aa Sponsor11 Proposal Jamaica
 
ท่องเที่ยวเชิงประวัติศาสตร์
ท่องเที่ยวเชิงประวัติศาสตร์ท่องเที่ยวเชิงประวัติศาสตร์
ท่องเที่ยวเชิงประวัติศาสตร์
 
20070901.mydomain
20070901.mydomain20070901.mydomain
20070901.mydomain
 
Meals on Wheels
Meals on WheelsMeals on Wheels
Meals on Wheels
 
Principales monedas
Principales monedasPrincipales monedas
Principales monedas
 
Cja 463 policy development paper
Cja 463 policy development paperCja 463 policy development paper
Cja 463 policy development paper
 
Federal Legislative and Regulatory Update
Federal Legislative and Regulatory UpdateFederal Legislative and Regulatory Update
Federal Legislative and Regulatory Update
 
Media Placement Portfolio Lindsay Krupa
Media Placement Portfolio  Lindsay KrupaMedia Placement Portfolio  Lindsay Krupa
Media Placement Portfolio Lindsay Krupa
 
Actividades quandary
Actividades quandaryActividades quandary
Actividades quandary
 
Life with gene
Life with geneLife with gene
Life with gene
 
บุคลากรครูที่เกษียณ12
บุคลากรครูที่เกษียณ12บุคลากรครูที่เกษียณ12
บุคลากรครูที่เกษียณ12
 
A common word
A common wordA common word
A common word
 

Semelhante a Inheritance

Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++RAJ KUMAR
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfstudy material
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCEVenugopalavarma Raja
 
Chapter18 class-and-objects
Chapter18 class-and-objectsChapter18 class-and-objects
Chapter18 class-and-objectsDeepak Singh
 
Access controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesAccess controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesVinay Kumar
 
Class&objects
Class&objectsClass&objects
Class&objectsharivng
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objectskhaliledapal
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++Mohamad Al_hsan
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Enam Khan
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++Shweta Shah
 

Semelhante a Inheritance (20)

11 Inheritance.ppt
11 Inheritance.ppt11 Inheritance.ppt
11 Inheritance.ppt
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 
chapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdfchapter-7-classes-and-objects.pdf
chapter-7-classes-and-objects.pdf
 
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCECLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
CLASSES AND OBJECTS IN C++ +2 COMPUTER SCIENCE
 
inheritance
inheritanceinheritance
inheritance
 
OOPs & C++ UNIT 3
OOPs & C++ UNIT 3OOPs & C++ UNIT 3
OOPs & C++ UNIT 3
 
class c++
class c++class c++
class c++
 
Chapter18 class-and-objects
Chapter18 class-and-objectsChapter18 class-and-objects
Chapter18 class-and-objects
 
4 Classes & Objects
4 Classes & Objects4 Classes & Objects
4 Classes & Objects
 
Access controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modesAccess controlaspecifier and visibilty modes
Access controlaspecifier and visibilty modes
 
C++ Notes
C++ NotesC++ Notes
C++ Notes
 
Class and object
Class and objectClass and object
Class and object
 
Class&objects
Class&objectsClass&objects
Class&objects
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
C++ presentation
C++ presentationC++ presentation
C++ presentation
 
+2 CS class and objects
+2 CS class and objects+2 CS class and objects
+2 CS class and objects
 
object oriented programming language by c++
object oriented programming language by c++object oriented programming language by c++
object oriented programming language by c++
 
C++ classes
C++ classesC++ classes
C++ classes
 
Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.Presentation on class and object in Object Oriented programming.
Presentation on class and object in Object Oriented programming.
 
Inheritance in C++
Inheritance in C++Inheritance in C++
Inheritance in C++
 

Último

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 

Último (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 

Inheritance

  • 1.
  • 2. The OO principle of inheritance enables you to create a generalized class and then derive more specialized classes from it.  Inheritance is the ability to take on the characteristics of the class or derived class on which it is based.  Specifies an “is-a” kind of relationship
  • 3. Person Employee Student Full-time Part-time Employee Employee
  • 4. Shape Rectangle Circle Square
  • 5. New classes that we create from the existing class are called derived classes; the existing classes are called base classes.
  • 6. class className:memberAccessSpecifier baseClassName { memberList; };  Where:  memberAccessSpecifier – is public, private, or protected. When no memberAccessSpecifier is specified, it is assumed to be a private inheritance.
  • 7. class Circle : public Shape { . . . };
  • 8. class Circle : private Shape { . . . };
  • 9. 1. The private members of a base class are private to the base class; hence the members of the derived class cannot directly access them. In other words, when you write the definitions of the member functions of the derived class, you cannot directly access the private members of the base class.
  • 10. 2. The public members of a base class can be inherited either as public members or as private members by the derived class. That is, the public members of the base class can become either public or private members of the derived class.
  • 11. 3. The derived class can include additional members – data and/or functions. 4. The derived class can redefine the public member functions of the base class. That is, in the derived class, you can have a member function with the same name, number and types of parameters as function in the base class. However, this redefinition applies only to the object of the derived class, not to the objects of the base class.
  • 12. 5. All member variables of the base class are also member variables of the derived class. Similarly, the member functions of the base class(unless redefined) are also member functions of the derived class. (Remember Rule 1 when accessing a member of the base class in the derived class.
  • 13. class Derived:Base class Base { { int y; int x; public : public : void print() const; void print()const; }; }; void Derived::print()const void Base::print()const { { cout<<y<<endl; cout<<x<<endl; } }
  • 14. To redefine a public member function of a base class in the derived class, the corresponding function in the derived class must have the same name, number, and types of parameters.
  • 15. class RectangleType { public: void setDimension(double, double); double getLength()const; double getWidth() const; double area()const; double perimeter()const; void print()const; RectangleType(); RectangleType(double, double); private: double length; double width; };
  • 16. #include "RectangleType.h" double RectangleType::getLength #include<iostream> ()const using namespace std; { return length; void RectangleType::setDimension } (double l, double w) double RectangleType::getWidth { ()const if (l>=0) { length = l; return width; else } length =0; if (w>=0) width = w; else width = 0; }
  • 17. double RectangleType::area()const RectangleType::RectangleType(double l, { double w) return length * width; { } setDimension(l,w); double RectangleType::perimeter } ()const RectangleType::RectangleType() { { return 2*(length + width); length =0; } width =0; void RectangleType::print() const } { cout<<"Length = "<<length <<"Width = " <<width; }
  • 18.  Define a class named BoxType  BoxType contains data members that stores the length, width and height of a box.  It has the following member functions :  Function that sets the dimension of the box  Function that sets a value for each data member of the class  Function that returns the value of each data member of the class  Function that prints the values of the data members of the class  Function that computes and returns the area of the box  Function that computes and returns the volume of the box  Default constructor which initializes data members to 0  Parameterized constructor which initializes data member to a value set by the object of the class
  • 19. In general, while writing the definitions of the member functions of a derived class to specify a call to a public member function of the base class we do the following:  If the derived class overrides a public member function of the base class, then to specify a call to that public member function of the base class use the name of the base class followed by the scope resolution operator, ::, followed by the function name with the appropriate parameter list.
  • 20.  If the derived class does not override a public member function of the base class, you may specify a call to that public member function by using the name of the function and the appropriate parameter list.
  • 21. Recall:  private members of a class are private to the class and cannot be directly accessed outside the class. Only member functions of that class can access the private members.  If public, anyone can access that member  So for a base class to give access to a member to its derived class and still prevent its direct access outside the class, you must declare the member under the memberAccessSpecifier protected. ▪ The accessibility of a protected class is between public and private ▪ A derived class can directly access the protected members of the base class.
  • 22. Example: class B : memberAccessSpecifier A { : : };  memberAccessSpecifier is either private, public or protected
  • 23. If memberAccessSpecifier is public – that is inheritance is public - then:  The public members of A are public members of B. They can be directly accessed in class B.  The protected members of A re protected members of B. They can be directly accessed by the member functions of B.  The private members of A are hidden in B. They can be accessed by the member functions of B through the public and protected members of A.
  • 24. If memberAccessSpecifier is protected– that is inheritance is protected - then:  The public members of A are protected members of B. They can be accessed by the member functions of B.  The protected members of A are protected members of B. They can be accessed by the member functions of B.  The private members of A are hidden in B. They can be accessed by the member functions of B through the private or protected members of A.
  • 25. If memberAccessSpecifier is private– that is inheritance is private - then:  The public members of A are private members of B. They can be accessed by the member functions of B.  The protected members of A are private members of B. They can be accessed by the member functions of B.  The private members of A are hidden in B. They can be accessed by the member functions of B through the private or protected members of A.