2010-12-06 16 views
0

これは私の子クラスである:私は(スーパーおよそ子クラスで問題を抱えている)

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"); 
} 
} 

それは常に「見つけることができないと言いますsymble 'super'。 "

+1

を呼び出すために望んでいました。正確なコンパイルエラーをコピーして貼り付け、コードのどの行にあるのかを示します。 –

答えて

4

スーパークラスには、呼び出し元の署名と一致するコンストラクタが必要です。あなたは

public User (XYCoordination currentLocation, ....) { 
    super(currentLocation); 
} 

を持っているので、あなたがニーズを拡張している外国人のクラスが一致signature-

public Alien(YCoordination currentLocation) 
+0

もっと具体的になりますか?私は新しいです。 –

+1

@Charles Cai - あなたが以前に質問したことと同じことをあなたに話しました。 –

+0

@CharlesCai:このような質問を投稿する前に、JLSで与えられているようにJavaの基本をいくつか読まなければならないと思います。 –

0

あなたが言う
スーパー(currentLocation)とのコンストラクタを持っています。 スーパークラス(親クラス)のコンストラクタを、単一の引数currentLocationで呼び出します。しかし、あなたのスーパークラスAlienには、単一の引数currentLocationを受け入れるコンストラクタはありません。

Cannot find symbol superこの場合、次のことを意味します。単一のパラメータでスーパークラスのコンストラクタを呼び出そうとしていますが、単一のcurrentLocation引数を持つスーパークラスのコンストラクタを見つけることができません。

あなたは、おそらく私は*その*コンパイルエラーを引き起こすあなたのコードで何も見えないsuper(currentLocation, energyCanister, lifePoints)

関連する問題