python(继承父类、子类)

# Author:Sooele
class People:    #父类
    def __init__(self,name,age):
        self.name = name
    def eat(self):
        print("%s is eating.." %self.name)
    def sleep(self):
        print("%s is sleeping.." %self.name)
    def talk(self):
        print("%s is talking.." %self.name)
class Man(People):   #子类
    def piao(self):
        print("%s in piaoing..... 20s......done" % self.name)
    def sleep(self):
        People.sleep(self)    #调用父类方法
        print("man si sleeping")  #调用子类方法
class Woman(People):    #子类2
    def get_birth(self):
        print("%s in born a baby..." % self.name)

m1 = Man("Sooele",22)   ##定义子类1
m1.eat()     #
m1.piao()   #
m1.sleep()   #

m2 = Woman("Cooi",22)  #定义子类2
m2.get_birth()



###子类2不能调用子类1的方法
##子类1、子类2都可以调用父类方法

发表评论