It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center




已关闭8年。




我看不到这门简短的课的问题。我得到8类,接口(interface)或枚举预期的错误。谢谢
public class BankAccount {
public BankAccount {
    private double balance = 0;
}
public BankAccount(double balanceIn) {
    private double balance = balanceIn;
}

public double checkBalance {
    return balance;
}

public void deposit(double amount) {
    if(amount > 0) balance += amount;
}

public void withdraw(double amount) {
    if(amount <= balance) balance -= amount;
}
}

最佳答案

您在构造函数中声明了修饰符和字段。将其放置在ctor外部

public BankAccount(double balanceIn) {
    private double balance = 0;
}

应该
public class BankAccount
{
    private double balance = 0;
    public BankAccount(){}
}

public BankAccount {
    private double balance = 0;
}

也错了..它不是构造函数,您缺少()并删除
private double balance = 0;

关于java - 继续获取预期的错误类,接口(interface)或枚举,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12892718/

10-09 07:24
查看更多