Incompatible return type error java

后端 未结 5 1489
礼貌的吻别
礼貌的吻别 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:31

    Forst Error is that the return type of your meyhod is void and the method returns an int.

     public void setAccountNumber(int accountnumber) {
        return accountnumber;
     }
    

    Change it to :

     public int setAccountNumber(int accountnumber) {
        return accountnumber;
     }
    

    and the second thing is this is not a good name for a method which is used for getting the variable , change the name of method to :

     public int getAccountNumber(int accountnumber) { // why is this argument???
        return accountnumber;
     }
    

    One more thing, your method

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

    has the same error. It should be :

    public double deposit(double amount) { //change void to double
        return this.accountbalance + amount; //as suggested by SURESH ATTA
    }
    

提交回复
热议问题