9.4 PRIVATE DERIVATION

The second method of deriving from the base class is by using keyword private (in place of public). Such derivation is termed as a private derivation. Now the derived class definition would look like:

class Clock : private Time0    { private :  char strg[5]; // for AM PM public :      void setAMPM();    } ;

When we define clock in this way, following things happen:

  1. The public methods become private methods.

  2. The public data members become private member.

  3. As members of Time0, like hr, min and sec become private, they are not accessible outside the derived class. You will be able to see or modify them, only from methods of derived class.

The summary of the access of the base class members in the privately derived class ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.