0

I just want to make an object. But I don't know why this error comes up. I thought everything was right but constructor error pop up. And it said required String,String,int no argument. Why is that?

error: constructor Account in class Account cannot iven types required: String,String,int found: no arguments reason: actual and formal argument

My code

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();

    }
}
lealceldeiro
  • 14,342
  • 6
  • 49
  • 80
Wahab
  • 11

1 Answers1

0

Make your constructor public and initialize balance property

public Account(){
    accName = "No name found";
    accID = "No id found";
    balance = 0;
}
Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42