我只想做一个对象。但我不知道为什么会出现此错误。我以为一切都正确,但是弹出构造函数错误。它说必需的String,String,int没有参数。为什么会这样?
error: constructor Account in class Account cannot iven types required: String,String,int found: no arguments reason: actual and formal argument
我的代码
class Account{
private String accName;
private String accID;
private int balance;
private Account(){
accName = "No name found";
accID = "No id found";
}
private Account(String name, String id, int bal){
accName = name;
accID = id;
balance = bal;
}
private void Withdrow(int amount){
if(balance > amount)
{
balance = balance - amount;
System.out.println("Balance :"+balance);
}
else
System.out.println("Not Enough money");
}
private void deposit(int amount){
if(amount>0)
{
balance = balance + amount;
System.out.println("Balance :"+balance);
}
else
System.out.println("Error Deposit");
}
private void showInfo(){
System.out.println("Name :"+ accName);
System.out.println("ID :"+ accID);
System.out.println("Balance :"+ balance);
}
}
class Main{
public static void main(String args[]){
Account ac = new Account();
}
}
答案 0 :(得分:0)
公开您的构造函数并初始化balance
属性
public Account(){
accName = "No name found";
accID = "No id found";
balance = 0;
}