C++ Programming - OOPS Concepts - Discussion

Discussion Forum : OOPS Concepts - General Questions (Q.No. 39)
39.
Which of the following are available only in the class hierarchy chain?
Public data members
Private data members
Protected data members
Member functions
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
13 comments Page 2 of 2.

Rahul Shirsat said:   1 decade ago
It is so because.

In a hierarchy, there are several classes inheriting their respective parents.

First of all, protected member means : they can be accessible only by the class which is inheriting it. Father's own Child can only access the protected members of Father and not the cousins, neighbors or any other.

Take a simple example.

GA is grand-parent of A and GB is grand-parent of B resp.

Only A should know secret password of GA. So as B to GB. :) :).

Cherry said:   1 decade ago
@protected data members are available by default throughout the class hierarchy chain.

i.e., we are using the keyword protected before the data members of class.

And remaining data members of class available based on their visibility (either public or private).

SHILPA said:   1 decade ago
Can anybody explain why?


Post your comments here:

Your comments will be displayed after verification.