Abstract Shape Hierarchy with Rectangle and Triangle
hardQuestion 202Create 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, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
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.