Problem

Look at the following class declarations and answer the questions that follow them: pub...

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

Step-by-Step Solution

Request Professional Solution

Request Solution!

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.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT