• 【笔试题】面向对象小测试(一)


    没对象?没关系,new一个,赶紧来测试下自己new的技术如何吧。

    class Person(object):
        __country = 'China'
    def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
    def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
    def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) Person('林小花',18)  

    请直接说出上面代码结果及原因:

    class Person(object):
        __country = 'China'
    def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
    def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
    def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) print(gf.__country)

    请直接说出上面代码结果及原因:

    class Person(object):
        __country = 'China'
    def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
    def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
    def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) print(gf.age)

    请直接说出上面代码结果及原因:

    class Person(object):
        __country = 'China'
    def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
    def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
    def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) print(gf.__name)

    请直接说出上面代码结果及原因:

    class Person(object):
        __country = 'China'
    def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
    def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
    def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) gf.query() 

    请直接说出上面代码结果及原因:

    class Person(object):
        __country = 'China'
    def __init__(self,name,age): print('创建对象中。。。') self.__name = name self.age = age print('你的对象信息:'.center(30,'*')) self.__query() print('恭喜脱单。。。'.center(30,'*'))
    def query(self): print("country:%s"%self.__country) print("name:%s"%self.__name) print("age:%s"%self.age) self.__query()
    def __query(self): print("country:%s" % self.__country) print("name:%s" % self.__name) print("age:%s" % self.age) gf = Person('林小花',18) gf.__query()

    请直接说出上面代码结果及原因: 

    class Person(object):
        __country = 'China'
    
        def __init__(self,name,age):
            print('创建对象中。。。')
            self.__name = name
            self.age = age
            print('你的对象信息:'.center(30,'*'))
            self.__query()
            print('恭喜脱单。。。'.center(30,'*'))
    
        def query(self):
            print("country:%s"%self.__country)
            print("name:%s"%self.__name)
            print("age:%s"%self.age)
            self.__query()
    
        def __query(self):
            print("country:%s" % self.__country)
            print("name:%s" % self.__name)
            print("age:%s" % self.age)
    
    gf = Person('林小花',18)
    gf.__country = 'America'
    print("你女朋友的国籍是:",gf.__country)
    gf.query()
    print(gf._Person__country)
    gf._Person__country = 'America2'
    print("你女朋友的国籍是:",gf.__country)
    gf.query()
    print(gf._Person__country)  

    请直接说出上面代码结果及原因:

    class Person(object):
        __country = 'China'
        
        def __init__(self,name,age):
            print('创建对象中。。。')
            self.__name = name
            self.age = age
            print('你的对象信息:'.center(30,'*'))
            self.__query()
            print('恭喜脱单。。。'.center(30,'*'))
            
        def query(self):
            print("country:%s"%self.__country)
            print("name:%s"%self.__name)
            print("age:%s"%self.age)
            self.__query()
            
        def __query(self):
            print("country:%s" % self.__country)
            print("name:%s" % self.__name)
            print("age:%s" % self.age)
    
    gf = Person('林小花',18)
    gf.__name = 'Lili'
    print("你女朋友的名字是:",gf.__name)
    gf.query()
    print(gf._Person__name)
    gf._Person__name = 'Lili2'
    print("你女朋友的名字是:",gf.__name)
    gf.query()
    print(gf._Person__name)

    请直接说出上面代码结果及原因:

    提前祝君七夕happy。

    图片来源于网络,如有侵权,请联系删除。

  • 相关阅读:
    10.22(day11) Object类 异常
    10.19(day10)
    10.18(day9)内部类 抽象类 接口
    10.17(day8) Static关键字 包的使用 访问修饰符的权限 设计模式
    paho-mqtt error1: incorrect protocol version解决方法
    Python进阶-pickle/eval/exec
    关联分析算法Apriori和FP-Growth
    LOF聚类分析
    Python进阶-迭代器和生成器
    Linux常见坑
  • 原文地址:https://www.cnblogs.com/uncleyong/p/11283647.html
Copyright © 2020-2023  润新知