zoukankan      html  css  js  c++  java
  • 【笔试题】面向对象小测试(一)

    没对象?没关系,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。

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

  • 相关阅读:
    如何检查项目的需求是否完整
    Linux环境 Java内存快速查看
    字符串拼接性能比较出乎意料的结果
    MySQL 查看表大小
    五大机器学习微信公众号推荐
    如何用PYTHON代码写出音乐
    【转载】机器学习如门概览
    机器学习PAI为你自动写歌词,妈妈再也不用担心我的freestyle了(提供数据、代码)
    【转载】程序猿转型AI必须知道的几件事!
    如何拿到阿里算法校招offer
  • 原文地址:https://www.cnblogs.com/uncleyong/p/11283647.html
Copyright © 2011-2022 走看看