我正在進行一項調查,使用double來回答問題,但在擴展類中出現錯誤。子類中的double值問題
超類:
import java.io.Serializable;
public abstract class Question implements Serializable
{
protected String question;
protected int maxResponses;
protected int numResponses;
public Question(String q, int m)
{
question = q;
maxResponses = m;
numResponses = 0;
}
public abstract void askQuestion();
public abstract void displayResults();
}
,這裏是我的擴展類,這是DoubleQuestions:
import java.util.Scanner;
public class DoubleQuestions extends Question
{
private double[] responses;
public DoubleQuestions(double q, int m)
{
super(q,m); // ERROR: constructor Question in class Question cannot be applied to given types;
responses = new double[m];
}
@Override
public void askQuestion()
{
double response;
Scanner input = new Scanner(System.in);
System.out.print(question + " ");
input.nextLine(); //still have to "eat" the current response
response = input.nextLine(); // ERROR: incompatible types
responses[numResponses] = response;
numResponses++;
}
@Override
public void displayResults()
{
System.out.println(question);
for(int i = 0; i < numResponses;i++)
System.out.println(responses[i]);
}
}
錯誤標記爲在源代碼中的註釋。
你可以試試你收到什麼錯誤? –
Java不是Javascript。一個標籤就夠了。 – GhostCat
對我們來說沒有第23和第34行....我們需要錯誤信息msg –