Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Sample Solution: Java Code: / / Shape.java - Base class Shape public class Shape { public double calculateArea ( ) { } return 0 ;
Sample Solution:
Java Code:
Shape.java Base class Shape
public class Shape
public double calculateArea
return ; Default implementation returns
Circle.java Subclass Circle
public class Circle extends Shape
private double radius;
public Circledouble radius
this.radius radius;
@override
public double calculateArea
return Math.PI radius radius; Calculate area of circle
Rectangle.java Subclass Rectangle
public class Rectangle extends Shape
private double width;
private double height;
public Rectangledouble width, double height
this.width width;
this. height height;
@override
public double calculateArea
return width height; Calculate area of rectangle
Triangle.java Subclass Triangle
public class Triangle extends Shape
private double base;
private double height;
public Triangledouble base, double height
this. base base;
this.height height;
@override
public double calculateArea
Main.java Main class
public class Main
public static void mainString args
Circle circle new Circle;
System.out.printlnArea of Circle: circle.calculateArea;
Rectangle rectangle new Rectangle;
System.out.println
Area of Rectangle:
rectangle.calculateArea;
Triangle triangle new Triangle;
System.out.println
Area of Triangle:
triangle.calculateArea;
Output:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started