#Animal类的age、name、localtion定义成私有属性,并定义对应的方法修改和获取他们的值。
class Animal :
def __init__(self,name,age,localtion):
self.__name=name
self.__age=age
self.__localtion=localtion
def get_name (self):
return self.__name
def change_name (self,new_name):
self.__name=new_name
def get_age (self):
return self.__age
def change_age (self,new_age):
self.__age=new_age
def get_location (self):
return self.__localtion
def change_localtion(self,new_localtion):
self.__localtion=new_localtion
dog=Animal('dog',88,'郑州')
print(dog.get_name(),dog.get_location())
dog.change_localtion('北京')
print(dog.get_name(),dog.get_location())