Page 185 - DCAP404 _Object Oriented Programming
P. 185

Object-oriented Programming




                    Notes          9.2.3  Multiple Inheritance

                                   A class can inherit the attributes of two or more classes. This mechanism is known as ‘MULTIPLE
                                   INHERITANCE’. Multiple inheritance allows us to combine the features of several  existing
                                   classes as a starting point for defining new classes.

                                       !

                                     Caution  It is like the child inheriting the physical feature of one parent and the intelligence
                                     of another.
                                   The syntax of the derived class is as follows:



                                                   Class base1               Class base2
                                                   {                         {
                                                         //body1                   //body2
                                                   }                         }





                                                      Class derived : visibility base1, visibility base2
                                                      {
                                                            //body3
                                                      }





                                      Task  A direct base class cannot appear in the base list of a derived class more than once.
                                     Discuss.

                                   Where the visibility refers to  the access specifiers i.e. public, private or protected. Following
                                   program shows the multiple inheritance.
                                                 #  include  <  iostream.h>
                                                 #  include  <  conio.h>
                                                 class  father                //Declaration  of  base  class1
                                                 {
                                                 int  age;
                                                 char  name  [20];
                                                 public:
                                                        void  get  (  );
                                                        void  show  (  );
                                                 };
                                                 void  father  :  :  get  (  )
                                                 {
                                                        cout  <<  “your  father  name  please”;
                                                        cin  >>  name;




          178                               LOVELY PROFESSIONAL UNIVERSITY
   180   181   182   183   184   185   186   187   188   189   190