class Account {
//属性 定义
var firstName: String
var lastName: String
var balance: Double
var rate = 0.0
// 构造函数
init(firstName:String , lastName:String , balance: Double){
self.firstName=firstName
self.lastName=lastName
self.balance=balance
}
// 方便化的 构造函数
convenience init (){
self.init(firstName:"",lastName:"",balance:0.0 )
}
// 定义对象方法
func printBreakDown() {
var balance = "\(self.balance)"
println("printBreakDown ...\(self.firstName) \(self.lastName) \(balance)")
}
func interestOverYears(years: Int) ->(Double) {
return 0
}
}
//继承类
class CheckingAccount: Account {
//重载构造函数
override init(firstName: String, lastName: String, balance: Double) {
super.init(firstName: firstName, lastName: lastName, balance: balance)
self.rate = 4
}
//重构对象方法
override func interestOverYears(years: Int) ->(Double) {
return (rate * balance * Double(years)) / 100
}
}
var account=Account(firstName: "kai", lastName: "wang", balance: 1233.3)
account.printBreakDown()
var checkAccount = CheckingAccount(firstName: "kai", lastName: "wanbg", balance: 1300.0)
checkAccount.interestOverYears(10)
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。