class Person {
func run() {
print("向前全速奔跑")
}
}
let per = Person()
per.run()
class Teacher: Person {
func teach() {
print("上课要迟到了")
super.run()
}
}
let tea = Teacher()
tea.teach()
class Student: Person {
var name:String = "小明"{
willSet(new){
print("新的名字:\(new)")
}
didSet{
print("旧的名字:\(oldValue)")
}
}
override func run() {
print("体育课上跑了800米")
}
var height:String{
return "175cm"
}
lazy var age:String = "18岁"
init(name:String,age:String) {
super.init()
self.name = name
self.age = age
}
public func show() {
print("姓名:\(name),年龄:\(age),身高:\(height)")
}
deinit {
self.name = ""
self.age = ""
print("调用了析构函数")
}
}
var stu:Student? = Student(name: "小王", age: "20岁")
stu!.name = "小刚"
//stu.name = "小王"
stu!.run()
print(stu!.height)
stu!.show()
stu = nil