Олимпиадный тренинг

Задача . 16


Задача

Темы:
public abstract class Solid
{
 private String name;
//constructor
 public Solid(String solidName)
 { name = solidName; }
 public String getName()
 { return name; }
 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,
double h)
 {
 super(prismName);
 length = l;
 width = w;
 height = h;
 }
 public double volume()
 { return length * width * height; }
}

A program that tests these classes has the following declarations and assignments:
Solid s1, s2, s3, s4;
s1 = new Solid("blob");
s2 = new Sphere("sphere", 3.8);
s3 = new RectangularPrism("box", 2, 4, 6.5);
s4 = null;

How many of the above lines of code are incorrect?
(A) 0
(B) 1
(C) 2
(D) 3
(E) 4

time 1000 ms
memory 32 Mb
Правила оформления программ и список ошибок при автоматической проверке задач

Статистика успешных решений по компиляторам
Комментарий учителя