此测试运行但失败。不知道为什么?有一个长度为 1 的 Submarine 类。
@Test
public void testShipConstructor() {
assertTrue(Submarine.length == 1);
}
这是该类的代码:
public abstract class Ship {
private int size;
public static int length;
protected Ship(int size, String type, String shortForm) {
this.size = size;
this.setType(type);
this.shortForm = shortForm;
}
public static void setLength(int length) {
}
public int getLength() {
return length;
}
int getSize() {
return size;
}
}
public class Submarine extends Ship {
private final static int SIZE = 1;
/**
* * Constructor, sets inherited length variable.
*/
public Submarine() {
super(SIZE, "Submarine", "#");
}
}