Page 206 - DCAP404 _Object Oriented Programming
P. 206

Unit 9: Inheritance




          Obj.  getdata  ();                                                                    Notes


          getdata  ();


          }


          When the statement obj. getdata (); get executed, the function getdata () of the derived class i.e.
          of derived B get executed. This means, the derived class function overrides the base class function.
          The scope resolution (:: ) operator can be used to access base class function through an object of
          the derived class.


                 Example:
          Derived B obj;


          Obj. Base A:: getdata ();



          The above statements specify that the getdata () of base A is to be called.


          A base class function can be accessed from within the derived class by as follows also:



          Class derived B: public base A


          {



          Public:


          Void  getdata  ()


          {


          Base  A::  getdata  ();      //  call  getdata  ()  of  base  A



          }


          };








                                           LOVELY PROFESSIONAL UNIVERSITY                                   199
   201   202   203   204   205   206   207   208   209   210   211