-
修改 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())
print(peter.__name)
peter.eat()
-
執行程式:
#python3 runprogram.py
I am a human
I am a Asian!Peter
Traceback (most recent call last):
File "runprogram.py", line 6, in
print(peter.__name)
AttributeError: 'Asian' object has no attribute '__name'