Look at the following class declarations and answer the questions that follow them:
public class Shape
{
private double area;
public void setArea(double a)
{
area = a;
}
public double getArea()
{
return area;
}
}
public class Circle extends Shape
{
private double radius;
public void setRadius(double r)
{
radius = r;
setArea(Math.PI * r * r);
}
public double getRadius()
{
return radius;
}
}
a) Which class is the superclass? Which class is the subclass?
b) Draw a UML diagram showing the relationship between these two classes.
c) When a Circle object is created, what are its public members?
d) What members of the Shape class are not accessible to the Circle class’s methods?
e) Assume a program has the following declarations:
Shape s = new Shape();
Circle c = new Circle();
Indicate whether the following statements are legal or illegal:
c.setRadius(10.0);
s.setRadius(10.0);
System.out.println(c.getArea());
System.out.println(s.getArea());
We need at least 10 more requests to produce the solution.
0 / 10 have requested this problem solution
The more requests, the faster the answer.