类方法通过@classmethod装饰器实现,类方法和普通方法的区别是,类方法只能访问类变量,不能访问实例变量
class Animal:
__feature='delicious'
country='China'
def __init__(self,name,color):
self.name=name
self.color=color
@classmethod
def get_feature(cls):
print('所有动物都%s' % cls.__feature)
Animal.get_feature()