Polymorphism
1. What is polymorphic
By different instance of the class object obtained with a method call, perform different logic.
For example:
class H2O: DEF the __init__ (Self, type, TEM): self.type = type self.tem = TEM DEF turn_ice (Self): IF self.tem < 0: Print ( ' % S, ice cold become ' % Self. TEM) elif self.tem> 0: Print ( ' % S, the liquefied into water ' % self.tem) class Ice (H2O): Pass class water (H2O): Pass I1 = Ice ( '冰',-20) w1 = Water('水',20) def func(obj): obj.turn_ice() func(i1) func(w1)
operation result:
-20 , become frozen ice 20 , the water liquefied into a Process finished with exit code 0