定义类(封装)
添加Person.py文件,在文件中加Person类
def __init__(self,a,b): #构造函数
self.name=a
self.age=b
在Main.py文件中调用 实例化类
继承
添加Student.py,并且添加Student类,继承Person类所有的属性、函数。
在Main.py文件中调用 实例化类
import Student
stu =Student.Student("xiaoming",12,5)
stu.introduct()
多态(方法重写)
Person类和Studen类中同时添加myMethod函数
Main.py 中调用
import Student
stu =Student.Student("xiaoming",12,5)
stu.introduct()
stu.myMethod()
super(Student.Student,stu).myMethod()