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 1 of 2.

RengaraJ said:   5 years ago
Public members available in BOTH hierarchy chain and also main.

But protected members are ONLY available in hierarchy chain.
(3)

Muhil said:   6 years ago
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.

Siya said:   10 years ago
I am confused. Public members can also be available in hierarchy chain. If they are inherited publicly, privately, protected.

Poonam said:   1 decade ago
@Saksham if public members can be accessed it means it is available.

Saksham said:   1 decade ago
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.
(2)

Pa1 said:   1 decade ago
Satya is right. Question seem to be wrong because question is about availability not about access.

Abhishek singh said:   1 decade ago
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.

Satya said:   1 decade ago
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 ?
(1)

Rohan said:   1 decade ago
You can access public members in class hierarchy if they are inherited using public access specifier in multiple inheritance.

Navin said:   1 decade ago
Public members are also available throughout the class hierarchy chain.

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


Post your comments here:

Your comments will be displayed after verification.