//输出全部内容
let tea = Teacher()
tea.eat()
tea.teach()
var stu:Student! = Student(name: “小明”, age: “22岁”)
stu!.name=“小刚”
stu.eat()
print(stu.wegiht)
print(stu.age)
stu.show()
stu=nil
//创建一个类Student并继承与Person,定义属性name,在Student中监听属性name的setter和getter
var name:String = “小明”{
willSet(newvalue){
print(“新值:(newvalue)”)
}
didSet{
print(“旧值:(oldValue)”)
}
}
//在Student类中重写父类的eat方法,打印“吃了早餐”
override func eat() {
print(“吃了早餐”)
}
//在Student类中定义一个只读属性weight,体重“70kg”
var wegiht:String{
get{
return “70kg”
}
}
//在Student类中懒加载一个属性age用来年龄“22岁”,为Student类定一个构造函数,在函数内为所有属性赋值
var age:String = “22岁”
init(name:String,age:String) {
super.init()
self.name=name
self.age=age
}
//在Student类中定义一个show方法,用来打印学生信息,函数是公开访问的
func show() {
print(“名字:(name),性别:(age),体重:(wegiht)”)
}
//重写Student类的析构函数,在函数内实现所有属性的清空,并打印“调用了析构函数”
deinit {
self.name=""
self.age=""
print(“调用了析构函数”)
}