"""
运行时,调用不同类实例化的对象下的相同方法,实现的过程不一样
得到不同的结果
mylist.__len__()
mystring.__len__()
"""
class H2O:
def __init__(self,name,temp):
self.name = name
self.temp = temp
def turn_ice(self):
if self.temp<0:
print("[%s]水结成冰咯"%self.name)
elif self.temp>=0 and self.temp<100:
print("[%s]冰融化成水咯"%self.name)
elif self.temp>=100:
print("[%s]水蒸发咯"%self.name)
class Ice(H2O):
pass
class Water(H2O):
pass
class Steam(H2O):
pass
def turn_ice(obj):
obj.turn_ice()
ice = Ice("冰",-40)
water = Water("水",40)
steam = Steam("水蒸气",100000)
turn_ice(ice)
turn_ice(water)
turn_ice(steam)
网友评论