Page 192 - DCAP404 _Object Oriented Programming
P. 192

Unit 9: Inheritance




                         public:                                                                Notes
                                void  display  (void);};
                                void  result  :  :  display  (void)
                         {
                                total  =  part1  +  part2  +  score;
                                put_n  (  );
                                put_m  (  );

                                put_s  (  );
                                cout  <<  “Total  score:  “<<total<<  “\n”;
                         }
                         main  (  )
                         {
                         clrscr  (  );
                                result  S1;

                                S1.get_n  (347);
                                S1.get_m  (30,  35);
                                S1.get_s  (7);
                                S1.dciplay  (  );
                         }



             Did u know?  What are the advantages of inheritance?
             Inheritance offers the following advantages:
             Development model closer to real life object model with hierarchical relationships

             Reusability — facility to use public methods of base class without rewriting the same
             Extensibility — extending the base class logic as per business logic of the derived class
             Data hiding — base class can decide to keep some data private so that it cannot be altered
             by the derived class.
          Self Assessment


          Fill in the blanks:
          5.   In “single inheritance,” a common form of inheritance, classes have only one ……………….
               class.

          6.   When a derived class privately inherits a base class, all the public members of the base
               class become …………………….. for the derived class.
          7.   The base class from which each class is derived is declared before the declaration of the
               …………………… class.
          8.   An indirect base class is a base class that does not appear directly in the …………………….
               of the derived class but is available to the derived class through one of its base classes.



                                           LOVELY PROFESSIONAL UNIVERSITY                                   185
   187   188   189   190   191   192   193   194   195   196   197