首页 > 代码库 > 实验:类的继承
实验:类的继承
1 class SchoolMember: 2 def __init__(self,name,age): 3 self.name = name 4 self.age = age 5 print ‘Initialized SchoolMember:%s‘%self.name 6 7 def tell(self): 8 print ‘Name:%s Age:%s‘%(self.name,self.age) 9 10 class Teacher(SchoolMember):11 def __init__(self, name, age,salary):12 SchoolMember.__init__(self, name, age)13 self.salary = salary14 print ‘Initialized Teacher:%s‘%self.name15 16 def tell(self):17 print ‘Salary:%d‘%self.salary18 19 class Student(SchoolMember):20 def __init__(self, name, age,marks):21 SchoolMember.__init__(self,name,age)22 self.marks = marks23 print ‘Initialized Student %s‘%self.name24 25 def tell(self):26 print ‘Marks %s‘%self.marks27 28 t = Teacher(‘Mars‘,40,3000)29 s = Student(‘Sw‘,18,88)30 31 t.tell()32 s.tell()
实验:类的继承
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。