Look at the following class declarations and answer the questions that follow them: public class Shape {

Question:

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());

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Question Posted: