import java.util.HashMap; class Room1 { private String description; private HashMap<String, Room1> dir = new HashMap<String, Room1>(); Room1(String de) { description = de; } public String toString() { return description; } public void add(String s, Room1 r) { dir.put(s, r); } } class Game { Room1 lobby = new Room1("lobby"); Room1 pub = new Room1("pub"); lobby.add("one", pub); //syntax error }当我调用 add 方法时,eclipse 告诉我存在错误。我很困惑。我找不到问题。
3 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
您必须在函数中调用这些方法。
class Game {
Room1 lobby = new Room1("lobby");
Room1 pub = new Room1("pub");
public Game() {
lobby.add("one", pub);
}
}
慕神8447489
TA贡献1780条经验 获得超1个赞
使用正确的语法
public class testing {
public static void main(String arg[]) {
Room1 lobby = new Room1("lobby");
Room1 pub = new Room1("pub");
lobby.add("one", pub);
}
}
添加回答
举报
0/150
提交
取消