โ Back to Inheritance
Question 433
Protected Helper Method
Protected Helper Method
Aprotectedmethod can be called by a derived class but not from outside the hierarchy. Base classCalculator(already written) has a PROTECTED methodint square(int x) constreturningx * x. Create a derived classStatsCalculatorwith a PUBLIC methodint squarePlusOne(int x) constthat returnssquare(x) + 1by calling the inherited protected helper. For input5,square(5)is 25 and the result is 26, so the program prints: 26 Do NOT write a main function.
Expected Output:
26
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.