class Base:
def __init__(self):
self.__x = "a"
__private = 1024
count = 100
@classmethod
def rcount(cls):
print(Base.count)
@staticmethod
def sta_rcount():
print(Base.count + 1)
def free():
print("freedom")
class Derived(Base):
def test(self):
'''
测试私有类属性、私有实例属性可访问性
:return:
'''
print(Base._Base__private)
print(Derived._Base__private)
print(self._Base__x)
pass
b = Base()
dc1 = Derived()
# 类属性
print(b.count, dc1.count, Base.count, Derived.count)
# 类方法
dc1.rcount()
b.rcount()
Base.rcount()
Derived.rcount()
# 静态方法
dc1.sta_rcount()
b.sta_rcount()
Base.sta_rcount()
Derived.sta_rcount()
# 自由方法
Base.free()
Derived.free()
# 私有类属性
print(Base._Base__private, Derived._Base__private, b._Base__private, dc1._Base__private)
dc1.test()
#私有实例属性
print(b._Base__x, dc1._Base__x)
来源:CSDN
作者:视觉未入门
链接:https://blog.csdn.net/qq_33941843/article/details/104017225