โ 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: 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.