zoukankan      html  css  js  c++  java
  • Python------继承

    class people:
        def __init__(self,name,gender,address,country):
            self.__name=name
            self.__gender=gender
            self.__address=address
            self.__country=country
            self.__info=[self.__name,self.__gender,self.__address,self.__country]
        def getName(self):
            return self.__name
        def getGender(self):
            return self.__gender
        def getAddress(self):
            return self.__address
        def getCountry(self):
            return self.__country
    class people2(people):
        def __init__(self,name,address,country="马来西亚"):    #“马来西亚”为设置的默认值
            self.__name=name
            self.__address=address
            self.__gender=""
            self.__country=country
            people.__init__(self,self.__name,self.__gender,self.__address,self.__country)
    pe=people("苏苏","","陕西省","China")
    print pe.getName()
    print "******************"
    pe2=people2("小周","山西省","越南")
    print pe2.getName()
    print pe2.getGender()
    print pe2.getAddress()
    print pe2.getCountry()
    print "/*/*/*/*/*/*/*/*/*"
    pe3=people2("小海","海南")
    print pe3.getName()
    print pe3.getAddress()
    print pe3.getCountry()

    【无法继承私有成员!】

    结果:

    苏苏
    ******************
    小周

    山西省
    越南
    /*/*/*/*/*/*/*/*/*
    小海
    海南
    马来西亚

  • 相关阅读:
    在Linux CentOS 6.6上安装Python 2.7.9
    CentOS yum 安装LAMP PHP5.4版本
    yum 安装php环境
    如何在Eclipse配置PyDev插件
    vagrant使用小结
    虚拟机下安装CentOS6.5系统教程
    python
    library cahce pin
    利用分析函数删除重复数据
    组合索引避免索引扫描后在过滤
  • 原文地址:https://www.cnblogs.com/soyo/p/8438506.html
Copyright © 2011-2022 走看看