โ Back to Inheritance
Question 548
Base Method Calls Override
Base Method Calls Override
Characterhas avirtualmethodNamereturning"hero"and a non-virtual methodAttackthat returnsName() + " attacks". CreateBossthat overridesNameto return"boss". WhenAttackruns on aBoss, it must call the overriddenName. Do NOT write aMainmethod. For aBossthe program prints: boss attacks For a plainCharacterit prints: hero attacks
Expected Output:
boss attacks
Topics:
Inheritance
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.