Java Reference
In-Depth Information
}
public void g()
{
super.g(); // 2
}
. . .
}
Which of them is an example of polymorphism?
΢΢΢Exercise R10.12. Consider this program:
public class AccountPrinter
{
public static void main(String[] args)
{
SavingsAccount momsSavings
= new SavingsAccount(0.5);
CheckingAccount harrysChecking
= new CheckingAccount(0);
. . .
endOfMonth(momsSavings);
endOfMonth(harrysChecking);
printBalance(momsSavings);
printBalance(harrysChecking);
}
public static void endOfMonth(SavingsAccount
savings)
{
savings.addInterest();
}
public static void endOfMonth(CheckingAccount
checking)
{
checking.deductFees();
}
public static void printBalance(BankAccount
account)
{
System.out.println(ÐThe balance is $Ñ
+ account.getBalance());
}
}
491
492
Search WWH ::




Custom Search