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.

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)

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)

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).

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.

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.

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).

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

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

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)


Post your comments here:

Your comments will be displayed after verification.