Page 211 - DCAP404 _Object Oriented Programming
P. 211

Object-oriented Programming




                    Notes          Self Assessment

                                   Fill in the blanks:
                                   15.  The destruction of the base class object named unicycle is no problem, its destructor is
                                       executed and the ………………….. is gone.

                                   16.  In a  multi-level inheritance,  the ……………………  will  be  executed in  the  order  of
                                       inheritance.

                                   9.8 Making a Private Member Inheritable


                                   The members of base class which are inherited by the derived class and their accessibility is
                                   determined by visibility modes. Visibility modes  are:
                                   1.  Private: When a base class is privately inherited by a derived class, ‘public members’ of
                                       the  base class become private members of the derived class and  therefore the  public
                                       members of the base class can be accessed by its own objects using the dot operator. The
                                       result is that we have  no member of base  class that is accessible  to the objects of the
                                       derived class.

                                   2.  Public: On the other hand, when the base class is publicly inherited, ‘public members’ of
                                       the base class become ‘public members’ of derived class and therefore they are accessible
                                       to the objects of the derived class.
                                   3.  Protected: C++ provides a third visibility modifier, protected, which serve a little purpose
                                       in the inheritance. A member declared as protected is accessible by the member functions
                                       within its class and any class immediately derived from it. It cannot be accessed by functions
                                       outside these two classes.

                                   The below mentioned table summarizes how the visibility of members undergo modifications
                                   when they are inherited.
                                                      Table  9.2: Execution  of base  Class  Constructors


                                           Base Class Visibility          Derived Class Visibility
                                                                   Public       Private      Protected
                                                 Private             X            X             X
                                                 Public            Public       Private      Protected
                                                Protected         Protected     Private      Protected

                                   The private and protected members of a class can be accessed by:
                                   1.  A function i.e. friend of a class.

                                   2.  A member function of a class that is the friend of the class.
                                   3.  A member function of a derived class.

                                   Self Assessment

                                   Fill in the blanks:
                                   17.  A member declared as ……………………. is accessible by the member functions within its
                                       class and any class immediately derived from it.







          204                               LOVELY PROFESSIONAL UNIVERSITY
   206   207   208   209   210   211   212   213   214   215   216