我有父类和子类,并试图实例化子类以继承父类的属性。
这段代码运行得很好,但想知道是否有办法让 self.list1 保持私有,即;如果我声明 self.__list1 则子类无法访问它。
我可以重写 childclass 方法以将 self.__list1 保持为私有吗?
class parent(object):
    def __init__(self,x,y):
        self.x = x
        self.y = y
        self.list1 = ['a','b','c']
        print('self.x',self.x)
        print('self.y',self.y)
class child(parent):
    def test(self):
        print('In child self.x',self.x)
        print('In child self.list1',self.list1)
class test(object):
    def __init__(self,x1,y1):
        self.x1 = x1
        self.y1 = y1
    def process(self):
        childobj = child(self.x1,self.y1)
        childobj.test()
        pass
def main():            
    testx = test(2,3)
    testx.process()