继续获得错误类,接口或枚举

时间:2012-10-15 09:25:48

标签: class interface enums compiler-errors

我看不出这个短课的问题。我得到8个类,接口或枚举预期错误。感谢

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

1 个答案:

答案 0 :(得分:2)

您在构造函数中声明了修饰符和字段。把它放在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;