首页 > 其他 > 详细

面向对象-组合

时间:2018-04-17 23:26:55      阅读:176      评论:0      收藏:0      [点我收藏+]

继承实现代码重用

class People:
    school="luffcity"
    def __init__(self, name, age, sex,):
        self.name = name
        self.age = age
        self.sex = sex

class Teacher(People):
    schoole=Luffycity
    def __init__(self,name,age,sex,level,salary):
        super(Teacher,self).__init__(name,age,sex)
        self.level=level
        self.salary=salary
    def teach(self):
        print("%s is teaching" % self.name)
class Student(People):
    schoole = Luffycity
    def __init__(self, name, age, sex, class_time):
        super(Student, self).__init__(name, age, sex)
        self.class_time=class_time
    def learn(self):
        print("%s is learning" % self.name)
t1=Teacher(alex,18,male,10,3000)
s1=Student(zhangsan,28,female,08:30:00)

 

面向对象-组合

原文:https://www.cnblogs.com/yaya625202/p/8870657.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!