首页 > 代码库 > 实验:类的继承

实验:类的继承

 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()

 

实验:类的继承