If I have an array of an object that has subclasses, can I access methods in the subclasses through calling the array?
This is a method in my Banking class, I would like to set the checking:
public void deposit() throws IOException {
BufferedReader br;
String entered_amount;
System.out.print("How much would you like to deposit? :");
br = new BufferedReader(new InputStreamReader(System.in));
entered_amount = br.readLine();
double amount = Double.valueOf(entered_amount).doubleValue();
balance = balance + amount;
System.out.println("Your balance is: " + getBalance());
Here is my Checking class:
public class Checking extends Bankaccount {
private double balance;
public Checking() {
}
public Checking(double balance) {
this.balance = balance;
}
/**
* @return the balance
*/
public double getBalance() {
return balance;
}
/**
* @param balance the balance to set
*/
public void setBalance(double balance) {
this.balance = balance;
}
}
When calling baArray[0]
in my main class is there a way to make deposit set the value of balance within the checking class?
The reason I'm doing this is because I'm writing out the array of objects to a file and rereading them when the program starts. I need to be able to store 3 sets of checking and savings. My deposit method would be what i'm trying to edit to use inheritance to set the balance in checking.