Question: Diagram 1: Class Polygon with subclasses (Class Triangle & Rectangle) 1. Write a Java program to declare all classes depicted in diagram 1 with their

Diagram 1: Class Polygon with subclasses (Class Triangle \& Rectangle) 1. Write a Java program to declare all classes depicted in diagram 1 with their attibutes and method implementations. Methods getArea() and calcArea()will return the following value: (a) Class Polygon getArea() will return 0 (b) Class Triangle getArea() will return the area of triangle based on formula: Area = 21 height width (c) Class Rectangle calcArea() will return the area of rectangle based on formula: Area = height width 2. Define a constructor for the class Polygon. In the constructor, assign the value of 5 as the initial value to all attributes. 3. Write a separate file ( which contains main method) to instantiate objects from Polygon, Triangle and Rectangle. Call the required methods to calculate the area of each object and display the results on the output screen
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
