'''
重写:子类和父类出现同名的函数,子类覆盖掉父类的函数
当子类函数即想拥有父类的也想自己新添加功能
高内聚低耦合:自己的事情自己做,类与类之间最好产生少的联系
继承好处:省代码 多态的前提
坏处:高耦合
super() 函数是用于调用父类(超类)的一个方法。
'''
class Person:
def __init__(self):
self.name=0
def eat(self):
print("吃苹果")
class Person1:
def eat(self):
print("吃西瓜")
class Man(Person1,Person):
def eat(self):
super().eat()
Person.eat(self)
Person1.eat(self)
print("吃香蕉")
m=Man()
m.eat()
重写(super函数)
猜你喜欢
转载自blog.csdn.net/feiYu12138/article/details/81747359
今日推荐
周排行