我只是在我的课程中进行继承,这是我用它做的第一个错误。除了在错误部分中抛出标题的构造函数之外,大多数代码都在工作。
public class CellDoor extends CellPassage {
// TODO: instance variable(s)!
private String imageOpen,imageClosed;
private boolean locked, occupied;
private Item item;
// Create a new cell in the dungeon with the specified image.
// The CellDoor class represents an door that can be closed (locked) or open.
// NOTE: an open door is allowed to hold an item (e.g. a gem or key).
public CellDoor(String imageOpen, String imageClosed, boolean locked) {
this.imageOpen = imageOpen;
this.imageClosed = imageClosed;
this.locked = locked;
}
cellPassage构造函数是:
public CellPassage(String image) {
this.image = image;
}
有人可以给我一些指示吗?
答案 0 :(得分:1)
你可能在CellPassage
类中有一个不是默认值的构造函数。这意味着Java无法通过调用默认的超级构造函数来创建CellDoor
对象。您必须在构造函数体的第一行中添加super(...)
,其中...是CellPassage
类中构造函数的参数。
public CellDoor(String imageOpen, String imageClosed, boolean locked)
{
super(imageOpen);
this.imageOpen = imageOpen;
this.imageClosed = imageClosed;
this.locked = locked;
}
如果您提供类CellPassage
中的代码,我们将很容易确定您应该如何编写CellDoor
构造函数