1. 程式人生 > >Python------繼承

Python------繼承

ret font blog -- 結果 style elf 無法 color

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()

【無法繼承私有成員!】

結果:

蘇蘇
******************
小周

山西省
越南
/*/*/*/*/*/*/*/*/*
小海
海南
馬來西亞

Python------繼承