32.3k views
1 vote
What is the difference between Public, Private, and Protected inheritance

A) Access levels for class members in the derived class
B) Control over member visibility in the base class
C) Inheritance modes for virtual functions
D) None of the above

User Intgr
by
7.9k points

1 Answer

5 votes

Final answer:

Public, Private, and Protected inheritance dictate the accessibility of base class members in the derived class. Public keeps the access same, Private makes all members private, and Protected turns public and protected members into protected within the derived class. The answer is A) Access levels for class members in the derived class. Option A is correct.

Step-by-step explanation:

The differences between Public, Private, and Protected inheritance in object-oriented programming (e.g., C++) pertain to the access levels for class members in the derived class, effectively determining how the inherited members of the base class can be accessed in the derived class.

In Public inheritance, the public and protected members of the base class retain their access levels in the derived class. Therefore, public members of the base class are public in the derived class, and protected members remain protected.

In Private inheritance, all members of the base class become private members of the derived class. This means that public and protected members of the base class are not accessible from outside the derived class, although the derived class itself can still access them.

In Protected inheritance, both public and protected members of the base class become protected in the derived class. This allows the derived class and its children to access these members, but not from outside these classes.

User Enavuio
by
8.0k points