这是我的孩子班:
public class User extends Alien
{
protected XYCoordination currentLocation;
protected int energyCanister;
protected int lifePoints;
public User (XYCoordination currentLocation, int energyCanister, int lifePoints)
{
super(currentLocation);
}
public int collectCanister()
{
super.collectCanister();
return energyCanister;
}
public int caculateLifePoints(int lifePoints)
{
super.caculateLifePoints(lifePoints);
return lifePoints;
}
}
这是我的父类:
public class Alien
{
protected XYCoordination currentLocation;
protected Planet currentPlanet;
protected int energyCanister;
protected int lifePoints;
protected int n;
public Alien(XYCoordination currentLocation, int energyCanister, int lifePoints)
{
this.currentLocation = currentLocation;
this.energyCanister = energyCanister;
this.lifePoints = lifePoints;
}
public XYCoordination moveRight(XYCoordination toRight)
{
currentLocation = currentLocation.addXToRight(toRight);
return currentLocation;
}
public XYCoordination moveUp(XYCoordination toUp)
{
currentLocation = currentLocation.addYToUp(toUp);
return currentLocation;
}
public XYCoordination moveLeft(XYCoordination toLeft)
{
currentLocation = currentLocation.addXToLeft(toLeft);
return currentLocation;
}
public XYCoordination moveDown(XYCoordination toDown)
{
currentLocation = currentLocation.addYToDown(toDown);
return currentLocation;
}
public int collectCanister()
{
energyCanister = energyCanister + (int)(n*currentPlanet.getRemainingCanister());
return energyCanister;
}
public int caculateLifePoints(int lifePoints)
{
lifePoints = (int)((2/3)*lifePoints);
return lifePoints;
}
public void displayInfo()
{
System.out.print("Currently you are in:" + currentLocation + "\t Currently you have" + energyCanister + "canisters" + "\tCurrently you have" + lifePoints + "lifepoints");
}
}
总是说“找不到'超级''。”
答案 0 :(得分:4)
你的超类需要有一个与你正在调用的签名相匹配的构造函数。你有
public User (XYCoordination currentLocation, ....) {
super(currentLocation);
}
您正在扩展的Alien类需要具有匹配签名的构造函数 -
public Alien(YCoordination currentLocation)
答案 1 :(得分:0)
当你说
时
超级(currentLocation);
使用单个参数currentLocation
调用超类(父类)构造函数。但是你的超类Alien没有一个接受单个参数currentLocation
的构造函数。
Cannot find symbol super
表示:您正在尝试使用单个参数调用超类构造函数,但我无法在超类中使用单个currentLocation
参数找到构造函数。 / p>
您可能想要致电super(currentLocation, energyCanister, lifePoints)