Question
Consider the following code. class BankAccount { var accountBalance: Float var accountNumber: Int init(number: Int, balance: Float) { accountNumber = number accountBalance = balance }
Consider the following code.
class BankAccount {
var accountBalance: Float
var accountNumber: Int
init(number: Int, balance: Float) {
accountNumber = number
accountBalance = balance
}
func displayBalance() {
print("Number \(accountNumber)")
print("Current balance is \(accountBalance)")
}
}
class SavingsAccount: BankAccount {
var interestRate: Float = 0.0
init(number: Int, balance: Float, rate: Float) {
super.init(number: number, balance: balance)
interestRate = rate
}
func calculateInterest() -> Float {
return interestRate * accountBalance
}
override func displayBalance() {
super.displayBalance()
print("Prevailing interest rate is \(interestRate)")
}
}
let savings1 = SavingsAccount(number: 17932020, balance: 1001.00, rate: 0.109)
print(savings1.calculateInterest())
savings1.displayBalance()
a) What is the output of the above code?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started