2012-10-15 82 views
1

我看不到這個短類的問題。我得到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; 
} 
} 
+0

你或許應該標記這與實際的語言(Java?)。 –

回答

2

您在構造函數中聲明瞭一個修飾符和字段。將它放置在構造函數外

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

應該

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

public BankAccount { 
    private double balance = 0; 
} 

也有錯..它是不是你缺少一個構造函數()和remove

private double balance = 0; 
+0

謝謝,這是我失蹤的一組空白。愚蠢的錯誤。謝謝! – user1746605

+0

甜,我通常不會說這個,但你可以接受它作爲你的答案:p –

相關問題