SlideShare uma empresa Scribd logo
1 de 16
Lecture 19



Public, Protected, and
  Private Inheritance
Inheritance -
                 Introduction
• Definition :Deriving methods and Data from an
  existing class to a new class .
• Use : we don’t need to redefine them in the
  new class. (Reusability)    Class A {
• Inheritance access control:         Data Members ;
                                       Member Functions
  – Private                            }
  – Protected                  Class B : public A
                                        {
  – Public                              Data Members;
                                        Member Functions
                                        }
B                  D

           Three Types of Access Control
     Suppose B is a super class and D is derived from B then

    If private inheritance, then all the members of B which are
    protected or public will be private in D.

    If protected inheritance, then all the members of B which
    are protected or public will be protected in D.

    If public inheritance, then all the members of B which are
    protected will also be protected in D and all the members of
    B which are public will also be public in D.
Private Inheritance

                     Class B
                        protected: int x
                        public: void f1()




                 Class D: private B
                     private: int y
                     public: void f2()


• int x and void f1() will be private in Class D.
If a member is private in what places it can be accessed?
            Same Class and friends of the Class
Protected Inheritance

                      Class B
                         protected: int x
                         public: void f1()




                  Class D: protected B
                      private: int y
                      public: void f2()


• int x and void f1() will be protected in Class D.
If a member is Protected in what places it can be accessed?
Same Class and friends of the Class,derived class and its friends
Public Inheritance

                    Class B
                       protected: int x
                       public: void f1()




                Class D: public B
                    private: int y
                    public: void f2()


• int x will be protected in Class D.
• void f1() will be public in Class D.
• What about Private data members ?
Sample Program
#include <iostream.h>
class Patient {                                 void InPatient::InSetdetails (int Wnum, int
    public:                                     Dys)
      void Setdetails(int, char);               { Wardnum = Wnum;
      void Displaydetails();                        Daysinward = Dys;
    private:                                    }
      int IdNumber; char Name; };
void Patient::Setdetails (int Idnum, char       void InPatient :: InDisplaydetails ()
    Namein)                                     { cout << endl << "Ward Number is "
{ IdNumber = Idnum; Name =                            << Wardnumber;
    Namein; }                                      cout << endl << "Number of days in
void Patient::Displaydetails()                  ward "
{ cout << endl << IdNumber << Name; }                 << Daysinward;
                                                }
class InPatient :     public          Patient   void main()
    {     public:                               {        InPatient p1;
          void InSetdetails (int, int);                  p1.Setdetails(1234, 'B');
          void InDisplaydetails();                       p1.Displaydetails();
                                                         p1.InSetdetails(3,14);
    private:
                                                         p1.InDisplaydetails();
          int Wardnum, Daysinward; };           }
Sample Program from Lecture 18:
            Change public to protected inheritance
#include <iostream.h>                              private:
class Patient {                                               int Wardnum, Daysinward;   };
    public:
      void Setdetails(int, char);                  void InPatient::InSetdetails (int Wnum, int
      void Displaydetails();                       Dys)
    private:                                       { Wardnum = Wnum;
      int IdNumber; char Name; };                      Daysinward = Dys;
void Patient::Setdetails (int Idnum, char          }
    Namein)                                        void InPatient :: InDisplaydetails ()
{ IdNumber = Idnum; Name = Namein; }               { cout << endl << "Ward Number is "
void Patient::Displaydetails()                           << Wardnumber;
{ cout << endl << IdNumber << Name; }                 cout << endl << "Number of days in
                                                   ward "
class InPatient : protected            Patient {         << Daysinward;
          public:                                  }
       void InSetdetails (int, int);               void main()
       void InDisplaydetails();                    {        InPatient p1;
                                                              p1.Patset();
      void Patset() { Setdetails(4321, ‘X’); }                p1.PatDisp();
      void PatDisp() { Displaydetails(); }                    p1.InSetdetails(3,14);
                                                              p1.InDisplaydetails();     }
Sample Program from Lecture 18:
             Change public to private inheritance
#include <iostream.h>                             void InPatient::InSetdetails (int Wnum, int Dys)
class Patient {                                   { Wardnum = Wnum;
    public:                                           Daysinward = Dys;
       void Setdetails(int, char);                }
       void Displaydetails();
    private:                                      void InPatient :: InDisplaydetails ()
       int IdNumber; char Name; };                { cout << endl << "Ward Number is "
void Patient::Setdetails (int Idnum, char               << Wardnumber;
    Namein)                                          cout << endl << "Number of days in ward "
{ IdNumber = Idnum; Name = Namein; }                    << Daysinward;
void Patient::Displaydetails()                    }
{ cout << endl << IdNumber << Name; }             void main()
                                                  {         InPatient p1;
class InPatient : private            Patient {              p1.Patset();
    public:                                                 p1.InSetdetails(3,14);
       void InSetdetails (int, int);                        p1.InDisplaydetails();
       void InDisplaydetails();                   }
       void Patset() { Setdetails(4321, ‘X’); }
    private:
                                                  We can access Setdetails() inside
           int Wardnum, Daysinward; };            Inpatient though it is private to
                                                  Inpatient but public to Patient.
Base-class and Derived-class
                Constructor and Destructor

• When an object of derived class is created the base class
  constructor is called first and then the derived class
  constructor is called.
  Example // Program1
• If the derived-class constructor is omitted, the derived class’s
  default constructor ( which is System Generated ) calls the
  base-class’s default constructor Program 2

• Destructors are called in the reverse order of constructor
  calls, so a derived-class destructor is called before its base-
  class destructor.
Person

   Student                                Lecturer



int main()                       Person’s object is created
{      Person Pers1;             Person’s object is created
       Student Stud1;            Student’s object is created
       Lecturer Lec1;            Person’s object is created
}                                Lecturer’s object is created
Base-class Initialiser: Sample Program 1 -
      Explicit Constructor definition
#include <iostream.h>                          void main() {
class Base {                                             Base b1;
   protected: int x, y;                                  b1.set();
   public:
     Base () {cout<<"Constructing Base                    Derived d1;
     object"<<endl;}                                      d1.set();
     ~Base() {cout<<"Destructing Base          }
     object"<<endl;}
     void set() { x = 10; y = 20;               Output:
                  cout<<x<<y<<endl;}
};                                                   Constructing Base object
class Derived : public Base {                        10 20
    private: int a, b;
    public:                                          Constructing Base object
      Derived() {cout<<"Constructing Derived         Constructing Derived object
     object"<<endl;}                                 40 60
      ~Derived() {cout<<"Destructing Derived
     object"<<endl;}                                 Destructing Derived object
      void set() { a = 40; b = 60;                   Destructing Base object
                    cout<<a<<b<<endl; }              Destructing Base object
};
Base-class Initialiser: Sample Program 1
        (No user-defined constructor for
                  derived class)
#include <iostream.h>                     void main() {
class Base {                                        Base b1;
   protected: int x, y;                             b1.set();
   public:
     Base () {cout<<"Constructing Base               Derived d1;
     object"<<endl;}                                 d1.set();
     ~Base() {cout<<"Destructing Base     }
     object"<<endl;}
     void set() { x = 10; y = 20;          Output:
                  cout<<x<<y<<endl;}
};                                              Constructing Base object
class Derived : public Base {                   10 20
    private: int a, b;
    public:                                     Constructing Base object
      void set() { a = 40; b = 60;              40 60
                    cout<<a<<b<<endl; }
};                                              Destructing Base object
                                                Destructing Base object
Base-class Initialiser



• A base-class initialiser can be provided in the derived-class
  constructor to call the base-class constructor explicitly;

• otherwise, the derived class’s constructor will call the base
  class’s default constructor implicitly.
Base-class Initialiser: Sample
                               Program 2
#include <iostream.h>                         class Circle: public Point {
class Point {                                 public:
public:                                                  Circle(double, int, int); //constructor
                                                         ~Circle();             //destructor
    Point (int, int); //constructor           private:
    ~Point();           //destructor                     double radius;
protected:                                    };
    int x, y;
                                              Circle::Circle(double r, int a, int b) : Point(a,b)
};
                                              { radius = r;
Point::Point(int a, int b)                       cout<<"Circle constructor: radius is
{ x = a; y = b;                                  "<<radius<<'['<<x<<", "<<y<<']'<<endl;
    cout<<"Point constructor: "<<'['<<x<<",   }
    "<<y<<']';
cout<<endl; }                                 Circle::~Circle()
                                              { cout<<"Circle destructor: radius is
                                                 "<<radius<<'['<<x<<", "<<y<<']'<<endl;
Point::~Point()                               }
{ cout<<"Point destructor: "<<'['<<x<<",
    "<<y<<']'; cout<<endl; }
Base-class Initialiser: Sample
                              Program 2 (cont.)
int main()                           Output:
{ {
             Point p(11, 22);            Point constructor: [11, 22]
                                         Point destructor: [11, 22]
    }
    cout<<endl;                          Point constructor: [72, 29]
    Circle circle1(4.5, 72, 29);         Circle constructor: radius is 4.5 [72, 29]
    cout<<endl;
                                         Point constructor: [5, 5]
    Circle circle2(10, 5, 5);
                                         Circle constructor: radius is 10 [5, 5]
    cout<<endl;
    return 0;                            Circle destructor: radius is 10 [5, 5]
}                                        Point destructor: [5, 5]

                                         Circle destructor: radius is 4.5 [72, 29]
                                         Point destructor: [72, 29]

Mais conteúdo relacionado

Mais procurados (20)

Python – Object Oriented Programming
Python – Object Oriented Programming Python – Object Oriented Programming
Python – Object Oriented Programming
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16Lecture 6, c++(complete reference,herbet sheidt)chapter-16
Lecture 6, c++(complete reference,herbet sheidt)chapter-16
 
Defining classes-part-i-constructors-properties
Defining classes-part-i-constructors-propertiesDefining classes-part-i-constructors-properties
Defining classes-part-i-constructors-properties
 
06 inheritance
06 inheritance06 inheritance
06 inheritance
 
Object oriented programming in python
Object oriented programming in pythonObject oriented programming in python
Object oriented programming in python
 
Object oriented programming with python
Object oriented programming with pythonObject oriented programming with python
Object oriented programming with python
 
201005 accelerometer and core Location
201005 accelerometer and core Location201005 accelerometer and core Location
201005 accelerometer and core Location
 
Introduction to DI(C)
Introduction to DI(C)Introduction to DI(C)
Introduction to DI(C)
 
JavaYDL10
JavaYDL10JavaYDL10
JavaYDL10
 
C# 3.0 Language Innovations
C# 3.0 Language InnovationsC# 3.0 Language Innovations
C# 3.0 Language Innovations
 
Python oop third class
Python oop   third classPython oop   third class
Python oop third class
 
Xdebug confoo11
Xdebug confoo11Xdebug confoo11
Xdebug confoo11
 
Ch8(oop)
Ch8(oop)Ch8(oop)
Ch8(oop)
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
OOP in PHP
OOP in PHPOOP in PHP
OOP in PHP
 
Object Oriented PHP5
Object Oriented PHP5Object Oriented PHP5
Object Oriented PHP5
 
Java2
Java2Java2
Java2
 
Java Persistence API
Java Persistence APIJava Persistence API
Java Persistence API
 
Entity api
Entity apiEntity api
Entity api
 

Destaque

Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...cprogrammings
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Anil Bapat
 

Destaque (7)

Lecture4
Lecture4Lecture4
Lecture4
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 
Inheritance
InheritanceInheritance
Inheritance
 
Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++Static and Dynamic polymorphism in C++
Static and Dynamic polymorphism in C++
 
Inheritance
InheritanceInheritance
Inheritance
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Semelhante a Lecture 19 - Three Types of Inheritance Access Control

Semelhante a Lecture 19 - Three Types of Inheritance Access Control (20)

Lecture20
Lecture20Lecture20
Lecture20
 
Inheritance in C++.ppt
Inheritance in C++.pptInheritance in C++.ppt
Inheritance in C++.ppt
 
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
 
Lec 42.43 - virtual.functions
Lec 42.43 - virtual.functionsLec 42.43 - virtual.functions
Lec 42.43 - virtual.functions
 
Lecture07
Lecture07Lecture07
Lecture07
 
More on Classes and Objects
More on Classes and ObjectsMore on Classes and Objects
More on Classes and Objects
 
Lecture4
Lecture4Lecture4
Lecture4
 
Classes and object
Classes and objectClasses and object
Classes and object
 
C++ prgms 4th unit Inheritance
C++ prgms 4th unit InheritanceC++ prgms 4th unit Inheritance
C++ prgms 4th unit Inheritance
 
Lec 30.31 - inheritance
Lec 30.31 -  inheritanceLec 30.31 -  inheritance
Lec 30.31 - inheritance
 
Lecture4
Lecture4Lecture4
Lecture4
 
Inheritance
InheritanceInheritance
Inheritance
 
inhertance c++
inhertance c++inhertance c++
inhertance c++
 
class and objects
class and objectsclass and objects
class and objects
 
OOPS 22-23 (1).pptx
OOPS 22-23 (1).pptxOOPS 22-23 (1).pptx
OOPS 22-23 (1).pptx
 
Mattbrenner
MattbrennerMattbrenner
Mattbrenner
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
20070329 Object Oriented Programing Tips
20070329 Object Oriented Programing Tips20070329 Object Oriented Programing Tips
20070329 Object Oriented Programing Tips
 
Unit 4
Unit 4Unit 4
Unit 4
 
Inheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybridInheritance_with_its_types_single_multi_hybrid
Inheritance_with_its_types_single_multi_hybrid
 

Mais de elearning_portal (10)

Lecture05
Lecture05Lecture05
Lecture05
 
Lecture17
Lecture17Lecture17
Lecture17
 
Lecture16
Lecture16Lecture16
Lecture16
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture09
Lecture09Lecture09
Lecture09
 
Lecture06
Lecture06Lecture06
Lecture06
 
Lecture03
Lecture03Lecture03
Lecture03
 
Lecture02
Lecture02Lecture02
Lecture02
 
Lecture01
Lecture01Lecture01
Lecture01
 
Lecture04
Lecture04Lecture04
Lecture04
 

Último

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxPoojaSen20
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfErwinPantujan2
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Jisc
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 

Último (20)

Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptxCulture Uniformity or Diversity IN SOCIOLOGY.pptx
Culture Uniformity or Diversity IN SOCIOLOGY.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdfVirtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
Virtual-Orientation-on-the-Administration-of-NATG12-NATG6-and-ELLNA.pdf
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...Procuring digital preservation CAN be quick and painless with our new dynamic...
Procuring digital preservation CAN be quick and painless with our new dynamic...
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 

Lecture 19 - Three Types of Inheritance Access Control

  • 1. Lecture 19 Public, Protected, and Private Inheritance
  • 2. Inheritance - Introduction • Definition :Deriving methods and Data from an existing class to a new class . • Use : we don’t need to redefine them in the new class. (Reusability) Class A { • Inheritance access control: Data Members ; Member Functions – Private } – Protected Class B : public A { – Public Data Members; Member Functions }
  • 3. B D Three Types of Access Control Suppose B is a super class and D is derived from B then If private inheritance, then all the members of B which are protected or public will be private in D. If protected inheritance, then all the members of B which are protected or public will be protected in D. If public inheritance, then all the members of B which are protected will also be protected in D and all the members of B which are public will also be public in D.
  • 4. Private Inheritance Class B protected: int x public: void f1() Class D: private B private: int y public: void f2() • int x and void f1() will be private in Class D. If a member is private in what places it can be accessed? Same Class and friends of the Class
  • 5. Protected Inheritance Class B protected: int x public: void f1() Class D: protected B private: int y public: void f2() • int x and void f1() will be protected in Class D. If a member is Protected in what places it can be accessed? Same Class and friends of the Class,derived class and its friends
  • 6. Public Inheritance Class B protected: int x public: void f1() Class D: public B private: int y public: void f2() • int x will be protected in Class D. • void f1() will be public in Class D. • What about Private data members ?
  • 7. Sample Program #include <iostream.h> class Patient { void InPatient::InSetdetails (int Wnum, int public: Dys) void Setdetails(int, char); { Wardnum = Wnum; void Displaydetails(); Daysinward = Dys; private: } int IdNumber; char Name; }; void Patient::Setdetails (int Idnum, char void InPatient :: InDisplaydetails () Namein) { cout << endl << "Ward Number is " { IdNumber = Idnum; Name = << Wardnumber; Namein; } cout << endl << "Number of days in void Patient::Displaydetails() ward " { cout << endl << IdNumber << Name; } << Daysinward; } class InPatient : public Patient void main() { public: { InPatient p1; void InSetdetails (int, int); p1.Setdetails(1234, 'B'); void InDisplaydetails(); p1.Displaydetails(); p1.InSetdetails(3,14); private: p1.InDisplaydetails(); int Wardnum, Daysinward; }; }
  • 8. Sample Program from Lecture 18: Change public to protected inheritance #include <iostream.h> private: class Patient { int Wardnum, Daysinward; }; public: void Setdetails(int, char); void InPatient::InSetdetails (int Wnum, int void Displaydetails(); Dys) private: { Wardnum = Wnum; int IdNumber; char Name; }; Daysinward = Dys; void Patient::Setdetails (int Idnum, char } Namein) void InPatient :: InDisplaydetails () { IdNumber = Idnum; Name = Namein; } { cout << endl << "Ward Number is " void Patient::Displaydetails() << Wardnumber; { cout << endl << IdNumber << Name; } cout << endl << "Number of days in ward " class InPatient : protected Patient { << Daysinward; public: } void InSetdetails (int, int); void main() void InDisplaydetails(); { InPatient p1; p1.Patset(); void Patset() { Setdetails(4321, ‘X’); } p1.PatDisp(); void PatDisp() { Displaydetails(); } p1.InSetdetails(3,14); p1.InDisplaydetails(); }
  • 9. Sample Program from Lecture 18: Change public to private inheritance #include <iostream.h> void InPatient::InSetdetails (int Wnum, int Dys) class Patient { { Wardnum = Wnum; public: Daysinward = Dys; void Setdetails(int, char); } void Displaydetails(); private: void InPatient :: InDisplaydetails () int IdNumber; char Name; }; { cout << endl << "Ward Number is " void Patient::Setdetails (int Idnum, char << Wardnumber; Namein) cout << endl << "Number of days in ward " { IdNumber = Idnum; Name = Namein; } << Daysinward; void Patient::Displaydetails() } { cout << endl << IdNumber << Name; } void main() { InPatient p1; class InPatient : private Patient { p1.Patset(); public: p1.InSetdetails(3,14); void InSetdetails (int, int); p1.InDisplaydetails(); void InDisplaydetails(); } void Patset() { Setdetails(4321, ‘X’); } private: We can access Setdetails() inside int Wardnum, Daysinward; }; Inpatient though it is private to Inpatient but public to Patient.
  • 10. Base-class and Derived-class Constructor and Destructor • When an object of derived class is created the base class constructor is called first and then the derived class constructor is called. Example // Program1 • If the derived-class constructor is omitted, the derived class’s default constructor ( which is System Generated ) calls the base-class’s default constructor Program 2 • Destructors are called in the reverse order of constructor calls, so a derived-class destructor is called before its base- class destructor.
  • 11. Person Student Lecturer int main() Person’s object is created { Person Pers1; Person’s object is created Student Stud1; Student’s object is created Lecturer Lec1; Person’s object is created } Lecturer’s object is created
  • 12. Base-class Initialiser: Sample Program 1 - Explicit Constructor definition #include <iostream.h> void main() { class Base { Base b1; protected: int x, y; b1.set(); public: Base () {cout<<"Constructing Base Derived d1; object"<<endl;} d1.set(); ~Base() {cout<<"Destructing Base } object"<<endl;} void set() { x = 10; y = 20; Output: cout<<x<<y<<endl;} }; Constructing Base object class Derived : public Base { 10 20 private: int a, b; public: Constructing Base object Derived() {cout<<"Constructing Derived Constructing Derived object object"<<endl;} 40 60 ~Derived() {cout<<"Destructing Derived object"<<endl;} Destructing Derived object void set() { a = 40; b = 60; Destructing Base object cout<<a<<b<<endl; } Destructing Base object };
  • 13. Base-class Initialiser: Sample Program 1 (No user-defined constructor for derived class) #include <iostream.h> void main() { class Base { Base b1; protected: int x, y; b1.set(); public: Base () {cout<<"Constructing Base Derived d1; object"<<endl;} d1.set(); ~Base() {cout<<"Destructing Base } object"<<endl;} void set() { x = 10; y = 20; Output: cout<<x<<y<<endl;} }; Constructing Base object class Derived : public Base { 10 20 private: int a, b; public: Constructing Base object void set() { a = 40; b = 60; 40 60 cout<<a<<b<<endl; } }; Destructing Base object Destructing Base object
  • 14. Base-class Initialiser • A base-class initialiser can be provided in the derived-class constructor to call the base-class constructor explicitly; • otherwise, the derived class’s constructor will call the base class’s default constructor implicitly.
  • 15. Base-class Initialiser: Sample Program 2 #include <iostream.h> class Circle: public Point { class Point { public: public: Circle(double, int, int); //constructor ~Circle(); //destructor Point (int, int); //constructor private: ~Point(); //destructor double radius; protected: }; int x, y; Circle::Circle(double r, int a, int b) : Point(a,b) }; { radius = r; Point::Point(int a, int b) cout<<"Circle constructor: radius is { x = a; y = b; "<<radius<<'['<<x<<", "<<y<<']'<<endl; cout<<"Point constructor: "<<'['<<x<<", } "<<y<<']'; cout<<endl; } Circle::~Circle() { cout<<"Circle destructor: radius is "<<radius<<'['<<x<<", "<<y<<']'<<endl; Point::~Point() } { cout<<"Point destructor: "<<'['<<x<<", "<<y<<']'; cout<<endl; }
  • 16. Base-class Initialiser: Sample Program 2 (cont.) int main() Output: { { Point p(11, 22); Point constructor: [11, 22] Point destructor: [11, 22] } cout<<endl; Point constructor: [72, 29] Circle circle1(4.5, 72, 29); Circle constructor: radius is 4.5 [72, 29] cout<<endl; Point constructor: [5, 5] Circle circle2(10, 5, 5); Circle constructor: radius is 10 [5, 5] cout<<endl; return 0; Circle destructor: radius is 10 [5, 5] } Point destructor: [5, 5] Circle destructor: radius is 4.5 [72, 29] Point destructor: [72, 29]