#继承实现
#父亲会书法, the older son and younger son can calligraphy.
#父亲一般能吃, the older son eats more than the youngest boy eats less
Class Father:
def write (self):
print ' I can write '
Class Oldbrother (father): #class A (B) subclass a inherits the parent class B
Def eat (self):
Print "I eat too Much"
Class Elderbrother (father):
def noeat (self):
Print "I can ' t eat"
Daerzi=oldbrother ()
Daerzi.write ()
Daerzi.eat ()
#多继承
Class Muniu:
Def eat (self):
print ' I can eat '
Class Gongniu:
def run (self):
print ' I can run '
Class Daniu (Muniu,gongniu): #class A (B,C,D)
Pass
Class Xiaoniu (Muniu):
Pass
Daniu=daniu ()
Daniu.eat ()
Daniu.run ()
Xiaoniu=xiaoniu ()
Xiaoniu.eat ()
#xiaoniu. Run ()
#多继承冲突, inherited from left to right (same time as parent method name)
Class Muniu:
Def eat (self):
print ' I can eat '
Class Gongniu:
def run (self):
print ' I can run '
Def eat (self):
print ' I can eat,too '
Class Daniu (Muniu,gongniu): #class A (B,C,D)
Pass
Daniu=daniu ()
Daniu.eat ()
The inheritance of the Python Foundation