CJCoding With Joseph

Shape Area Hierarchy

Build a small polymorphic hierarchy. The abstract class Shape declares int Area(). Create Rectangle (constructor int width, int height, area width * height) and Triangle (constructor int baseLen, int height, area (baseLen * height) / 2), each inheriting Shape and implementing Area(). The tester sums the areas in a Shape[]. Do NOT write a Main method.

For a Rectangle(2, 3) and a Triangle(4, 3) the program prints:
Total area: 12

Expected Output:

Total area: 12
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.