CJCoding With Joseph
15free / daySign inCreate account

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

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Abstract ClassesInheritanceClasses
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.