← Back to 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
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.