Page 177 - DCAP404 _Object Oriented Programming
P. 177

Object-oriented Programming




                    Notes          Self Assessment

                                   Fill in the blanks:
                                   1.  Inheritance is a mechanism of ……………………. and extending existing classes without
                                       modifying them, thus producing hierarchical relationships between them.

                                   2.  Inheritance is almost like embedding an ………………… into a class.
                                   3.  C++ allows you to use one class declaration, known as a base class, as the basis for the
                                       declaration of a second class, known as a ……………………..

                                   4.  A member marked as …………………….. is accessible from member functions of the class
                                       and also from member functions of any classes derived from that class.

                                   9.2 Forms of Inheritance


                                   9.2.1  Single Inheritance

                                   When a class inherits from a single base class, it is referred to as single inheritance. Following
                                   program shows single inheritance using public derivation.
                                          #include<iostream.h>
                                          #include<conio.h>

                                          class  worker
                                          {
                                          int  age;
                                                 char  name  [10];
                                          public:
                                                 void  get();
                                          };

                                          void  worker::get()
                                          {
                                                 cout  <<  “your  name  please”;
                                                 cin  >>  name;
                                                 cout  <<  “your  age  please”;
                                                 cin  >>  age;
                                          }
                                          void  worker::show()
                                          {

                                                 cout<<“\nMy  name  is  :”<<name<<“\nMy  age  is  :”<<age;
                                          }
                                          class  manager  :  public  worker          //derived  class  (publicly)
                                          {





          170                               LOVELY PROFESSIONAL UNIVERSITY
   172   173   174   175   176   177   178   179   180   181   182