Incompatible return type error java

后端 未结 5 1487
礼貌的吻别
礼貌的吻别 2021-01-17 06:52
class BankAccount {
    private String firstname;
    private String lastname;
    private int ssn;
    private int accountnumber = 0;
    private double accountbala         


        
5条回答
  •  执念已碎
    2021-01-17 07:19

    public void setAccountNumber(int accountnumber) {
        return accountnumber;
    }
    
    public void deposit(double amount) {
        return this.accountbalance=this.accountbalance+amount;
    }
    

    ...Are you trying to return in void-return function???

    This will be correct:

    public int setAccountNumber(int accountnumber) {
    //     ^^^
        return accountnumber;
    }
    
    public double deposit(double amount) {
    //     ^^^^^^
        return this.accountbalance=this.accountbalance+amount;
    }
    

提交回复
热议问题