python中类的简单继承及私有类的例子

# 测试类及类方法的继承
class A(object):
    def test1(self):
        print('testA1')
        self.__private_test_a3()
    def test2(self):
        print('testA2')
    # 私有方法,只能在该类里面被调用,不用在外面通过引用类然后掉用
    def __private_test_a3(self):
        print('testA3')
class B(A):
    def test3(self):
        print('testB3')
    def test1(self):
        print('testB1')
        self.test3()
a = A()
a.test1()
b = B()
b.test1()
b.test2()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容