码迷,mamicode.com
首页 > 其他好文 > 详细

实验:类的继承

时间:2014-12-09 01:49:26      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:style   blog   ar   color   sp   div   log   bs   ef   

 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 = salary
14         print Initialized Teacher:%s%self.name
15         
16     def tell(self):
17         print Salary:%d%self.salary
18         
19 class Student(SchoolMember):
20     def __init__(self, name, age,marks):
21         SchoolMember.__init__(self,name,age)
22         self.marks = marks
23         print Initialized Student %s%self.name
24         
25     def tell(self):
26         print Marks %s%self.marks
27         
28 t = Teacher(Mars,40,3000)
29 s = Student(Sw,18,88)
30 
31 t.tell()
32 s.tell()

 

实验:类的继承

标签:style   blog   ar   color   sp   div   log   bs   ef   

原文地址:http://www.cnblogs.com/predator-wang/p/4152309.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!