Design an abstract class called Shape. This class contains a single constructor
ID: 3924738 • Letter: D
Question
Design an abstract class called Shape. This class contains a single constructor that accepts a single numeric value that is used to calculate various values, one of which is area. Include an abstract method called findArea that can be defined to find the area of any shape. Also provide a concrete method to return the area.
Design two concrete classes, Circle and Square, that inherit the class Shape. Each of these classes finds the respective area; i.e. area of circle and area of square.
You are responsible for providing any relevant variable(s).
NB: You are NOT required to write a test class.
Explanation / Answer
abstract class Shape
{
private int a;
Shape(double a)
{
this.a=a;
}
abstract double findArea(double);
}
public class Circle extends Shape
{
Circle(double r)
{
super(r);
}
public double findArea()
{
return 3.14*a*a;
}
}
public class Square extends Shape
{
Square(double side)
{
super(side);
}
public double findArea()
{
return a*a;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.