← Back to Inheritance
Question 613
Shape Area Hierarchy
Shape Area Hierarchy
Build a small polymorphic hierarchy. TheabstractclassShapedeclaresint Area(). CreateRectangle(constructorint width, int height, areawidth * height) andTriangle(constructorint baseLen, int height, area(baseLen * height) / 2), each inheritingShapeand implementingArea(). The tester sums the areas in aShape[]. Do NOT write aMainmethod. For aRectangle(2, 3)and aTriangle(4, 3)the program prints the output shown in Expected Output.
Expected Output:
Total area: 12= newline. The output ends with a newline — print one after the last line.
Hints4 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 (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.