Design an abstract class called Shape This class contains a

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.

Solution

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;

}

}

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, on
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, on

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site