1. Wrote a castle game, suddenly reported an error, the subclass has inherited the method of the parent class, why also reported an error? And
2. Interface
package ChenBan;
public interface scene {
//
public void setExit(String name,scene room);
//
public String getExit();
//
public void res();
//
public void narration();
//
public String toString();
}
implement the interface
package ChenBan;
import java.util.HashMap;
public abstract class Room implements scene {
private String description;
private HashMap<String,scene> roomList=new HashMap<String,scene>();
public Room(String description){
this.description=description;
}
//
public void setExit(String name,scene room){
roomList.put(name, room);
}
//
public String getExit(){
StringBuffer s=new StringBuffer();
for(String str:roomList.keySet()){
s.append(str);
s.append(roomList.get(str));
s.append("");
}
if(roomList.isEmpty()){
System.out.println("");
}
return s.toString();
}
//
public Room getDirect(String direction){
Room ret=(Room)roomList.get(direction);
return ret;
}
//
public String toString(){
return this.description;
}
}
subclass
package ChenBan;
public class BedRoom extends Room{
public BedRoom(String description){
super(description);
}
@Override
public void res() {
// TODO Auto-generated method stub
}
@Override
public void narration() {
System.out.println("");
}
}
Business
package ChenBan;
public class Initial {
//
private scene currentRoom;
//
public void welcome(){
System.out.println("");
System.out.println("");
System.out.println(""go "");
System.out.println(""bye"");
System.out.println(""help"");
}
//
BedRoom bedRoom=new BedRoom("");
scene s=new BedRoom("");
FrontRoom frontRoom=new FrontRoom("");
Kitchen kRoom=new Kitchen("");
//
s.setExit();//
}
3.s.setExit (); error Syntax error on token "setExit", Identifier expected after this token
I don"t understand what"s wrong. Thank you first