首页 > 其他 > 详细

对类中私有化的理解

时间:2020-05-08 09:26:04      阅读:57      评论:0      收藏:0      [点我收藏+]
class Person(object):
    def __init__(self,name,age,taste):
        self.name = name
        self._age = age
        self.__taste = taste
    def showPerson(self):
        print(self.name)
        print(self._age)
        print(self.__taste)
    def do_work(self):
        self._work()
        self.__away()
    def _work(self):
        print("_work方法被调用")
    def __away(self):
        print("__away方法被调用")
class Student(Person):
    def construction(self,name,age,taste):
        self.name = name
        self._age = age
        self.__taste = taste
    def showStudent(self):
        print(self.name)
        print(self._age)
        print(self.__taste)
    @staticmethod
    def testbug():
        _Bug.showbug()
class _Bug(Student):
    @staticmethod
    def showbug():
        print("showbug函数开始运行")
s1 = Student(Xiaoming,22,basketball)
s1.showPerson()
# s1.showStudent()
# s1.construction( )
s1.construction(rose,18,football)
s1.showPerson()
s1.showStudent()
Student.testbug()
‘‘‘
Xiaoming
22
basketball
rose
18
basketball
rose
18
football
showbug函数开始运行
‘‘‘

2020-05-08

对类中私有化的理解

原文:https://www.cnblogs.com/hany-postq473111315/p/12846958.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!