← Back to Abstract Classes
Question 202
Abstract Shape Hierarchy with Rectangle and Triangle
Abstract Shape Hierarchy with Rectangle and Triangle
Create an abstract classShapewith an abstract methoddouble area()and a concrete methodString label()that returns"Shape". Then create two subclasses: 1.Rectangle— takeswidthandheight.area()returnswidth * height. Overridelabel()to return"Rectangle". 2.Triangle— takesbaseandheight.area()returns0.5 * base * height. Overridelabel()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
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.