← Back to Inheritance
Question 443
Protected Inheritance Access
Protected Inheritance Access
Withprotectedinheritance, 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 classBase(already written) has a publicint value() constreturning 42. Create a classMiddlethat inherits fromBaseusing PROTECTED inheritance, and add a public methodint reveal() constthat returnsvalue(). Outside code cannot callvalue()on aMiddle, butreveal()can. The program prints the output shown in Expected Output. Do NOT write a main function.
Expected Output:
42= newline. The output ends with a newline — print one after the last line.
Hints3 available
Sign in to use hintsTopics:
Inheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.