#! encoding=UTF-8
class A:
def say(self):
print self.name
print self.__age
class B(A):
def __init__(self):
self.name = "wangwu"
self.__age = 20
b = B()
b.say()
执行结果:
代码如下:
wangwu
Traceback (most recent call last):
File "C:\Users\lee\Documents\Aptana Studio 3 Workspace\testa\a.py", line 15, in
b.say()
File "C:\Users\lee\Documents\Aptana Studio 3 Workspace\testa\a.py", line 6, in say
print self.__age
AttributeError: B instance has no attribute '_A__age'