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());
Step by Step Answer:
Starting Out With Java From Control Structures Through Data Structures
ISBN: 9780133957051
6th Edition
Authors: Tony Gaddis