python学习,day5:继承

# 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 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)
m1.sleep()    #继承和重构sleep
m1.talk()     #继承talk
m1.piao()     #子类的piao
w1 = Woman('uu',22)
w1.piao()     #兄弟类不能继承

猜你喜欢

转载自www.cnblogs.com/bbgoal/p/11714611.html