Inheritance: Base classes & Derived Classes
e.g.
class ABC //base class
{ ……..//members of class ABC }
class XYZ : public ABC { ……//members of class XYZ }
|
|
Then, a derive class XYZ can be created as following:
|
|
class XYZ : private ABC { ……//members of class XYZ }
|
|
The colon indicates that the derived-class-name is derived from the base-class-name. The visibility-mode is optional and if present may be either private or public. The default visibility mode is private. Visibility mode specifies whether the features of the base class are privately derived or publicly derived. When a base class is privately inherited by a derived class, ‘public members’ of the base class become private members of derived class and therefore they are accessible only within derived class. When a base class is publicly inherited, ‘public members’ of the base class becomes ‘public members’ of the derived class. In both cases, the private members of base class are not inherited and therefore, the private members of a base class will never become the members of its derived class.
No comments:
Post a Comment