python学习,day6 继承

# coding=utf-8
# Author: RyAn Bi
class People:
    def __init__(self,name,age):
        self.name = name
        self.age = age
    def  talk(self):
        print('%s is talking'% self.name)
    def sleep(self):
        print('%s is loving sleep'% self.name)

class Man(People):       #继承
    def __init__(self,name,age,money):  #重构父类,不在调用上面的属性,所以属性要和上面父类一致(可以多),否则调用失败
        People.__init__(self,name,age)  #把父类里面有的,再执行一遍
        #super(Man,self)__init__(name,age)   #另外一种父类重构,好处是可以多继承,例如people有很多个
        self.money = money     #父类里没有的,单独定义一遍
    def sleep(self):
        People.sleep(self)     #重构父类
        print('%s is sleeping'% self.name)
    def piao(self):
        print("%s say hi baby,come on "%self.name)

class Woman(People):       #继承
    def get_birth(self):
        print('%s is birthing baby '%self.name)


m1 = Man('bb',22,10)
m1.sleep()    #继承和重构sleep
m1.talk()     #继承talk
m1.piao()     #子类的piao
w1 = Woman('uu',22)
w1.piao()     #兄弟类不能继承
posted @ 2020-01-13 09:02  bbgoal  阅读(114)  评论(0编辑  收藏  举报