CJCoding With Joseph

Build a Shape Hierarchy

Build a polymorphic shape hierarchy from scratch. Define an abstract class Shape with an abstract method int Area(). Then define three subclasses, each with a constructor and an Area() override:
- Square(int side) with area side * side
- Rectangle(int w, int h) with area w * h
- Triangle(int b, int h) with area b * h / 2
The tester stores them in a List<Shape> and sums their areas. Do NOT write a Main method.

For Square(2), Rectangle(3, 4), and Triangle(6, 4) (areas 4, 12, 12) the program prints:
28

Expected Output:

28
Topics:
Polymorphism
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.