Python继承练习

'''
#知识点1.覆盖父类方法,创建子类(优先找子类sleep)
#知识点2.子类继承父类方法(super().sleep())
class Animal(object):
def eat(self):
print("吃")

def sleep(self):
print("睡着了...")


class Dog(Animal):
# 覆盖父类方法
def sleep(self):
# 引用父类方法
super().sleep()
print("仰天大睡")

def bark(self):
print("狂吠")


class Cat(Animal):

def climetree(self):
print("爬树")


d1 = Dog()
#d1.sleep() # 睡着了... 仰天大睡
#d1.eat() # 吃

c1 = Cat()
c1.sleep() # 睡着了...
'''
posted @ 2022-04-15 23:09  呼长喜  阅读(157)  评论(0编辑  收藏  举报