-
修改 human.py 的內容:
#vim human.py
class Human():
def __init__(self):
self.name = "I am a Human"
def showName(self):
return self.name
def eat(self):
print("eating food ...")
-
修改 asian.py 的內容:
#vim asian.py
from human import Human
class Asian(Human):
def __init__(self,name):
super().__init__()
self.name = super().showName()+ "\n" + "I am a Asian!" + name
def showName(self):
return self.name
def eat(self):
print("eating rise food ...")
-
修改 runprogram.py 的內容:
#vim runprogram.py
from asian import Asian
from american import American
peter = Asian("Peter")
print(peter.showName())
peter.eat()
-
執行程式:
#python3 runprogram.py
I am a Human
I am a Asian!Peter
eating rise food ...