C++ Programming - OOPS Concepts - Discussion

Discussion :: OOPS Concepts - General Questions (Q.No.39)

39. 

Which of the following are available only in the class hierarchy chain?

[A]. Public data members
[B]. Private data members
[C]. Protected data members
[D]. Member functions

Answer: Option C

Explanation:

No answer description available for this question.

Shilpa said: (Jun 26, 2012)  
Can anybody explain why?

Cherry said: (Jul 3, 2012)  
@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).

Rahul Shirsat said: (Jul 21, 2012)  
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. :) :).

Navin said: (Jan 9, 2013)  
Public members are also available throughout the class hierarchy chain.

The point is how the class has been getting inherited (public, private or protected).

Rohan said: (Jul 5, 2013)  
You can access public members in class hierarchy if they are inherited using public access specifier in multiple inheritance.

Satya said: (Aug 28, 2013)  
All the private, public, and protected members are inherited in the class hierarchy. This depends on how the derived class is inherited using different access modifiers (public, protected, private).

Private members although inherited cannot be accessed in the derived classes whereas protected and public members are accessible in the derived classes.

So this statement seems wrong that only protected members are inherited in a class hierarchy. Could somebody please correct me if I'm wrong ?

Abhishek Singh said: (Feb 4, 2014)  
Public data member can also be accessed without the hierarchy chain while protected data member can be accessed by inheritance only that why only is being emphasized in question.

Pa1 said: (Mar 24, 2014)  
Satya is right. Question seem to be wrong because question is about availability not about access.

Saksham said: (Aug 27, 2014)  
Dear @Pa1 and @Satya, you should look at the question very carefully. It is asking- Which of the following are available **ONLY** in the class hierarchy chain?

Now public members can be accessed and modified directly from main function.

Private can neither be seen(from main()) nor inherited.

AND protected can not be seen from main() but can be inherited.
i.e. it is the only one that is available ONLY through the class hierarchy chain.

I hope this makes it clear.

Poonam said: (Oct 29, 2014)  
@Saksham if public members can be accessed it means it is available.

Siya said: (Feb 25, 2016)  
I am confused. Public members can also be available in hierarchy chain. If they are inherited publicly, privately, protected.

Muhil said: (Jul 26, 2019)  
The classes form a class hierarchy, or inheritance tree, which can be as deep as needed. The hierarchy of classes in Java has one root class, called Object, which is a superclass of any class. Instance variable and methods are inherited down through the levels.

Rengaraj said: (Jan 24, 2021)  
Public members available in BOTH hierarchy chain and also main.

But protected members are ONLY available in hierarchy chain.

Post your comments here:

Name *:

Email   : (optional)

» Your comments will be displayed only after manual approval.