Page 239 - AP Computer Science A, 7th edition
P. 239

public abstract double volume(); }
public class Sphere extends Solid {
private double radius;
//constructor
public Sphere(String sphereName, double sphereRadius)
{
super(sphereName);
radius = sphereRadius; }
public double volume()
{ return (4.0/3.0) ∗ Math.PI ∗ radius ∗ radius ∗ radius; }
}
public class RectangularPrism extends Solid {
private double length; private double width; private double height;
//constructor public RectangularPrism(String prismName, double l, double w,
{
}
public double volume()
{ return length ∗ width ∗ height; } }
super(prismName); length = l;
width = w;
height = h;
double h)
16. A program that tests these classes has the following












































































   237   238   239   240   241