面向对象父类和子类,私有属性
当父类只是实例数据,子类可以获得,但如果父类是私有属性数据,子类不能获得父类数据
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25class Animal: x=10 def Dog(self): print(Animal.x) print(self.x) p=Animal() p.Dog() class Dog1(Animal): def test2(self): print(Dog1.x,self.x) p1=Dog1() p1.test2() class Animal: __x=10 def Dog(self): print(Animal.__x) print(self.__x) p=Animal() p.Dog() class Dog1(Animal): def test2(self): print(Dog1.__x,self.__x) p1=Dog1() p1.test2()
最后
以上就是兴奋耳机最近收集整理的关于面向对象父类和子类,私有属性的全部内容,更多相关面向对象父类和子类内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复