【发布时间】:2013-05-31 02:48:44
【问题描述】:
如何调用扩展主类的类的 setter 和 getter。 我有我的主类 BankAccount,并且我有扩展 BankAccount 的 CheckingAccount
public class CheckingAccount extends BankAccount {
private double overdraftProtection;
public CheckingAccount(){
};
public CheckingAccount(String accountNo, String accountName,
double initBalance) {
super(accountNo, accountName, initBalance);
}
public CheckingAccount(String accountNo, String accountName) {
super(accountNo, accountName);
}
public double getOverdraftProtection() {
return overdraftProtection;
}
public void setOverdraftProtection(double overdraftProtection) {
this.overdraftProtection = overdraftProtection;
}
public void withdraw(double amount) {
// TODO: code for withdrawal
}
在我的 GUI 中,我想调用支票账户的 setter 和 getter。我已经尝试过account.setOverdraftProtection,但没有可用的。
我的图形用户界面:
private void btnSaveAActionPerformed(java.awt.event.ActionEvent evt) {
if(rad_savings.isSelected()){
account.setAccountType("Savings");
account.setInterest(Double.parseDouble(txt_interestrate.getText()));
}
else{
account = new CheckingAccount();
account.setAccountType("Checking");
}
【问题讨论】:
-
setOverdraftProtection()是每个BankAccount的实现都应该有的方法吗? -
不,accounttype 有一个单选按钮,如果选择了检查帐户,那是它唯一的实现时间。
-
你为什么打电话给
BankAccount你的主班? -
@Eric Jablow -- 抱歉,伙计,您能否进一步解释您的评论?
-
主类是什么意思?您是指具有
main方法的类吗?只是好奇。顺便问一下,你真的需要 setAccountType 方法吗?你拥有它的方式,有人可以创建一个CheckingAccount并在其上调用`setAccountType("Savings")。最好将其设为只读并仅使用 getter。
标签: java swing arraylist getter-setter