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

面向对象-组合

时间:2018-04-17 23:52:24      阅读:351      评论:0      收藏:0      [点我收藏+]

标签:hang   eve   school   sel   color   time   self   name   style   

继承实现代码重用

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)

 

面向对象-组合

标签:hang   eve   school   sel   color   time   self   name   style   

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

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