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) {
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
3.44 Rating (167 Votes )
There are 3 Steps involved in it
The Shape class is the superclass and the Circle class is the subclass The Circle cl... View full answer
Get step-by-step solutions from verified subject matter experts
