CJCoding With Joseph

Protected Inheritance Access

With protected inheritance, the base class's PUBLIC members become PROTECTED in the derived class: outside code can no longer call them, but the derived class's own methods still can.

Base class Base (already written) has a public int value() const returning 42.

Create a class Middle that inherits from Base using PROTECTED inheritance, and add a public method int reveal() const that returns value().

Outside code cannot call value() on a Middle, but reveal() can. The program prints:
42

Do NOT write a main function.

Expected Output:

42
Topics:
Inheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.