Page 180 - DCAP404 _Object Oriented Programming
P. 180

Unit 9: Inheritance




                         cin>>now;                                                              Notes
                 }
                 void  manager::show()
                 {
                 worker::show();
                 cout  <<  “\n  no.  of  worker  under  me  is  :  “<<now;
                 }
                 main()
                 {
                         clrscr();
                         worker  w1;
                         manager  m1;
                         m1.get();
                         m1.show();
                 }




             Notes  When a derived class publicly inherits the base class, all the public members of the
             base class also become public to the derived class and the objects of the derived class can
             access the public members of the base class.

          The following program shows the single inheritance using protected derivation
                         #include<conio.h>
                         #include<iostream.h>
                         class  worker                       //Base  class  declaration
                         {

          protected:
                                int  age;  char  name[20];
                         public:
                                void  get();
                                void  show();
                         };
                         void  worker::get()

                         {
                         cout  >>  “your  name  please”;
                         cin  >>  name;
                         cout  <<  “your  age  please”;
                         cin  >>  age;
                         }




                                           LOVELY PROFESSIONAL UNIVERSITY                                   173
   175   176   177   178   179   180   181   182   183   184   185