Page 198 - DCAP404 _Object Oriented Programming
P. 198

Unit 9: Inheritance




          }                                                                                     Notes


          void  result::total()
          {
                 tmarks=msub1+msub2+msub3+smarks;
          }



          void  result::display()
          {
                 cout<<“enroll:”<<enroll;
                 cout<<“\nname:”<<name;
                 cout<<“\ncourse:”<<course;
                 cout<<“\nexam  type:”<<etype;
                 cout<<“\ntotal  marks:”<<tmarks;

          }


          void  main()
          {
                clrscr();
                result  r1;
                r1.input();
                r1.total();
                r1.display();

                getch();
          }
          Self Assessment


          Fill in the blanks:
          11.  Deriving a class from more than one direct base class is called …………………  inheritance.
          12.  To use multiple inheritance, simply specify each base class (just like in single inheritance),
               separated by a……………………. .

          9.4 Virtual Base Classes

          We have just discussed a situation which would require the use of both multiple and multi level
          inheritance. Consider a situation, where all the three kinds of inheritance, namely multi-level,
          multiple and hierarchical are involved. Let us say the ‘child’ has two direct base classes ‘parent1’
          and ‘parent2’ which themselves has a common base class ‘grandparent’. The child inherits the
          traits of ‘grandparent’ via two separate paths. It can also be inherit directly as shown by the
          broken line. The grandparent is sometimes referred to as ‘INDIRECT BASE CLASS’. Now, the




                                           LOVELY PROFESSIONAL UNIVERSITY                                   191
   193   194   195   196   197   198   199   200   201   202   203