ClassCastException occurs when you attempt to cast an object of one data type to another type. Also, calling an object to a subclass of which it is not an instance.
(A) ((SavingsAccount) b).addInterest(); Does not match because b refers to BankAccount not SavingsAccount
(B) ((CheckingAccount) b).withdraw(200); Does not match because b refers to BankAccount not CheckingAccount
(C) ((CheckingAccount) c).deposit(800); Is the only one of the five statements that works because c refers to CheckingAccount and the statement is calling for a deposit in CheckingAccount
(D) ((CheckingAccount) s).withdraw(150); Does not match because s refers to SavingsAccount not CheckingAccount
(E) ((SavingsAccount) c).addInterest(); Does not match because c refers to CheckingAccount not SavingsAccount
(Does not match means it does not match with the subclass)
Nick Armold helped me with this challenge
Understood. I'll swing by.
ReplyDeletewe reviewed and talked about this concept
ReplyDelete