不知道爲什麼,但我得到了第一個大括號的語法錯誤,它說我需要在第一個變量聲明後添加一個大括號。不知道爲什麼我得到這個語法錯誤
public class DogNeeds extends PetNeeds {
super.setAnimalType("dog"); //This method is inherited from PetNeeds superclass
protected boolean walk;
public DogNeeds(String name) {
super(name);
// TODO Auto-generated constructor stub
}
boolean getWalk() {
return walk;
}
void setWalk(boolean walk) {
this.walk = walk;
}
public void walkDog() {
if(walk) {
System.out.println("Time to walk " + super.getName());
}
else {
System.out.println(super.getName() + " doesn't need to go out yet.");
}
}
}
在方法中放置'super.setAnimalType'語句 – Reimeus
在方法,構造函數或初始化程序塊之外不能有像'super.setAnimalType(「dog」)''這樣的行。 –