public class Bank Account private double balance public Bank Account balance 0;
ID: 3813830 • Letter: P
Question
public class Bank Account private double balance public Bank Account balance 0; public BankAccount double acctBalance) balance acctBalance; public void deposit (double amount) balance amount; public void withdraw (double amount) balance amount; public double getBalance return balance public clasa SavingsAccount extends BankAccount private double interestRatei Public SevingaAccount implementation not shown Y public savingsAccounts (double acctBalance, double rate) implementation not shown k/ public void addInterest //Add interest to balance t impleaentation not shown public class checkingAccount extends BankAccount private static final double FEE 2.0 private static final double MIN BALANCE 50.0; public CheckingAccount double acctBalance) implexentation not shown 1 FEE of $2 deducted if withdrawal leaves balance less than MIN BALANCE. Allows for negative balance. public void withdraw (double arnount) implementation not shownExplanation / Answer
In this question, see the method transfer(). It is taking an object of BankAccount class type. In the question, 3 statements are asked I, II and III. For these, there is no BankAccount object passed but in every statement, subclass object passed are of the sub-class of BankAccount so it is valid. You can pass sub-class as a super class target argument to a function because, inside the sub class, a super class object is also created.
So, you need to check the pre-conditions of all these 3 before transfer so that it can be determined whether the statement is valid or not.
b.transdfer(timeSavings, 50). In b, the balance is 650 so we can transfer 50 from it. So, statement I is correct.
timeSavings.transfer(daynasChecking, 30). This is also possible because the balance in timeSavings is 1500 so 30 can be deducted. Plus, in that class, nothing is mentioned as a constraint.
daynasChecking.transfer(b, 55). This is also possible as balance is 2000 and 55 is transfered. This class has an restriction over the balance that while withdrawal, balance goes below the minimum then charge $2 and can accept negative balance also but this is not required here because 2000 - 55 = 1945 and MIN_BALANCE = 50. So, no need to give the charge of $2.
So, as all the 3 statements are true, the answer is (D).
Please comment if there is any query, Thank you. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.