Page 94 - DCAP404 _Object Oriented Programming
P. 94

Unit 4: Classes and Objects




                          return sum;                                                           Notes
                      }
              };
          int  main()
              {
                  Calculator obj;
                  obj.num1 = 2;

                          ChildCalculator  myChildObj;
                          int  result  =  myChildObj.add();
                  cout << result;;
                  return 0;
              }
          An external function cannot access a protected member of a class (base class); however, a derived
          class method can access a protected member of the base class.





             Notes  A member of a class can access any member of  the same class independent of
             whether the member is public, protected or private.

          You should now know the role of the access specifiers: public, protected and private as applied
          to classes. In one of the following parts of the series, we shall see the role of the access specifiers
          in the declarator of a derived class.

          A public member of a class is accessible by external functions and a derived class. A private
          member of a class is accessible only by other members of the class; it is not accessible by external
          functions and it is not accessible by a derived class. A protected member of a class is accessible
          by a derived class (and other members of the class); it is not accessible by an external function.

          Self Assessment


          Fill in the blanks:
          12.  The access-specifier determines the access to the names that follow it, up to the next access-
               specifier or the end of the class……………………. .

          13.  A public member of a class is accessible by ……………………. functions and a derived
               class.
          14.  If a member of a class is……………………, it cannot be accessed by an external function;
               even a derived class cannot access it.
          15.  With the ……………………. access specifier,  an external function can access the public
               members of the class.












                                           LOVELY PROFESSIONAL UNIVERSITY                                   87
   89   90   91   92   93   94   95   96   97   98   99