CJCoding With Joseph
15per day

Abstract Shape Hierarchy with Rectangle and Triangle

Create an abstract class Shape with an abstract method double area() and a concrete method String label() that returns "Shape". Then create two subclasses:

1. Rectangle — takes width and height. area() returns width * height. Override label() to return "Rectangle".
2. Triangle — takes base and height. area() returns 0.5 * base * height. Override label() to return "Triangle".

Do NOT write a main method.

Expected Output:

Rectangle: 50.00
Triangle: 25.00
Topics:
Abstract ClassesInheritanceClasses
Code Editor
1
Tab to indent · Ctrl+Enter to run · Ctrl+Space to expand shortcuts (sysout, psvm, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.