Python does not support polymorphic
Code area:
1 classUniversitymember:2 def __init__(self, Name, age):3Self.name =name;4Self.age =Age ;5 6 #instance Method7 defGetName (self):8 returnSelf.name;9 Ten defgetage (self): One returnSelf.age; A - #subclass Student class inherits parent class - classStudent (universitymember): the def __init__(self, name, age, height): - #Show calling Parent class construction method -Universitymember.__init__(self, name, age); -Self.height =height; + - defgetheight (self): + returnSelf.height; A at #subclass Teacher class inherits parent class - classTeacher (universitymember): - def __init__(self, name, age, salary): - #Show constructor method for calling parent class -Universitymember.__init__(self, name, age); -Self.salary =salary; in - defgetsalary (self): to returnself.salary; + - #Instantiate student class theStudent = Student ('STU1', 100, 158); * Print(Student.getname ());#STU1 $ Print(Student.getage ());# -Panax Notoginseng Print(Student.getheight ());#158 - the #Instantiate teacher class +Teacher = Teacher ('tea1', 100, 99); A Print(Teacher.getname ());#tea1 the Print(Teacher.getage ());# - + Print(Teacher.getsalary ());# About
Python Object-oriented inheritance