I want to fill values in my arraylist of abstract class type.Below is my code
public abstract class Account {
private int accountId;
private int customerId;
private double balance;
public Account(int accountId, int customerId, double balance) {
this.accountId = accountId;
this.customerId = customerId;
this.balance = balance;
}
public abstract double deposit(double sum);
public abstract double withdraw(double sum);
}
Above is my abstract class.
Now I have another class bank in which i want to define and declare an arraylist in which i can fill my values .
I declared arraylist as
ArrayList<Account> al=new ArrayList<>();
Now i want to pass values to this arraylist for further use but i couldnot as we cannot instantiate abstract class.I tried this code to fill values in class with main method but couldnot get it because of above reason
Account ac= new Account(1,100,25000);
ArrayList<Account>ac= new ArrayList<Account>();
ac.add(ac);
Account(even an anonymous one if you want) . An abstract class has no use without concrete implementations, because some behavior has not been defined.Account ac= new Account(1,100,25000);is impossible. You have to create another class extending your abstract class.acvariable twice.