NIOS Computer Science: Chapter 14 – Inheritance Extending Classes Part 5

Download PDF of This Page (Size: 262K)

Image of Private visibility mode

Image of Private Visibility Mode

Image of Private visibility mode

The Private Visibility Mode

We are using the same example, but the derivation is done in private mode.

Class student

{

// same as in previous example

138 :: Certificate in Computer Science

};

class marks : private student

{

//

};

The following figure illustrates the private derivation in the classes.

Image of The Private Visibility Mode

Image of the Private Visibility Mode

Image of The Private Visibility Mode

The Protected visibility mode

We are using the same example but the derivation is done in protected mode.

class student

{

// same as in previous example

};

class marks : protected student

{

};

The following figure illustrates the protected derivation in the classes.

Image of The Protected visibility mode

Image of the Protected Visibility Mode

Image of The Protected visibility mode

The data present in private section of base class cannot be inherited. The difference between private and protected section is that data present in protected section can be inherited. Otherwise both the section cannot be accessed by the object of the class.