#成员修饰符:公有,私有
#公有在类中,子类,类外均可访问;私有只能在类中访问,子类和类外不可访问 class Foo: #私有字段只能类本身调用,子类和外部都不能调用 __cc = 123 def __init__(self,name,age): self.name = name self.__age = age def f1(self): print(self.__age) #静态方法调用类中的私有字段 @staticmethod def f2(): print(Foo.__cc) class Foo1(Foo): def f2(self): print(self.__name) obj = Foo("jiang") print(obj.name) obj.f1() obj = Foo1("chen") obj.f1() Foo.f2()