Professional Documents
Culture Documents
-----------------------------------------------
EXERCISE 1
2. Write the output from the test harness for class SavingsAccount.
SavingsAccount: balance $115.0, interest rate 0.15
EXERCISE 2
8. Does the program run after deleting the line causing the compilation
error? If the program crashed, why did it crash?
Yes it does, and the program crashed because bacc1 references a BankAccount object
not a CheckingAccount object.
11. Why does the compiler issue an error message when invoking
newAcc.getTransactionCount()? Why does the compiler issue an error message when
invoking newAcc.getInterestRate()?
The compiler looks at the variable type of newAcc which is BankAccount not the
specific type since that would be dependent on the if statement.
12. Can you tell whether in the statement String accountInfo = newAcc.toString();
the
method toString() being invoked is from the class CheckingAccount or from the class
SavingsAccount? Explain your answer.
The invocation would be dependent on whether the user chooses c (CheckingAccount)
or s (SavingsAccount)
If the user chooses c, then the method toString() will be invoked from class
CheckingAccount
If the user chooses s, then the method toString() will be invoked from class
SavingsAccount