我剛開始學習java,並不熟悉這門語言。這是一個在線任務,我爲了獲得樂趣並獲得更多的熟悉,並且無法弄清我在構造函數行中遇到的多個錯誤。請幫助此行有多個標記,Java構造函數錯誤(初學者級別)。
public class WhackAMole {
public static void main(String[] args) {
int score;
int molesLeft;
int attemptsLeft;
char [][]moleGrid=new char[10][10];
int numAttempts; //is this needed
int gridDimensions; // is this also needed
/*Multiple markers at this line
- Syntax error on token "int", delete this token
- Syntax error, insert ";" to complete Statement
- Syntax error on token "int", delete this token
- numAttempts cannot be resolved to a variable
- gridDimensions cannot be resolved to a variable
- Syntax error on token "int", delete this token
- The method WhackAMole(int, int) is undefined for the type
WhackAMole*/
WhackAMole(int numAttempts, int gridDimensions) {
this.numAttempts=numAttempts ; //error-cannot use this in static content
this.gridDimensions=gridDimensions ; // error-cannot use this in static content
}
}
}
你不關閉你的主要方法。在'int gridDimensions'之後;'添加一個'}'並從下面刪除1'}'。 –
您必須將構造函數和字段移出'main' – QBrute
您是混合方法和構造函數。 –