找不到符号 java

来源:百度知道 编辑:UC知道 时间:2024/05/31 04:00:49
class BallanceException extends Exception{ }

class Account{
private String name;
public double ballance;
public Account (String name){
this.name=name;
this.ballance=0;
}
public void debit(double d)throws
BallanceException{
if(ballance<d){throw new BallanceException();}
else{ballance-=d;}
}
}

class Text0{
public static void main(String[]args)
{Account a1=new Account("Tom");
a1.save(200);
try{a1.debit(500);}
catch(BallanceException ex)
{System.out.println("余额不足");}
}
}

你的Account 中有save方法么。。。。

Account类中没有 save 方法,
你在a1这个对象中调用save(200)会报错

在Account类中加个save方法就行了
public void save(int money){
ballance = ballance + money;
}