PCJ #
class Dog (Object):
DEF __init __ (Self, name):
self.name name =
DEF RUN (Self):
Print ( "% S will only ordinary play"% self.name)
class XiaoTiaoDog (Dog):
DEF RUN (Self):
Print ( "% S fly sky play" the self.name%)
class the Person (Object):
DEF the __init __ (Self, name):
the self.name = name
DEF game_with_dog (Self, Dog): # Chuan into an ordinary dog or flying dog, here is the key to
print ( "% s% s happy and play"% (self.name, dog.name))
# let the dog play
dog.run ()
# 1 to create a dog objects
# wangcai = dog ( "Cai")
wangcai = XiaoTiaoDog ( "Cai Fei")
# 2, Xiao Ming to create a target
xiaoming = Person ( "Bob")
# 3, so that the method Xiaoming and dog playing
xiaoming.game_with_dog(wangcai)
Polymorphic case presentations
Guess you like
Origin www.cnblogs.com/pcjbk/p/11235005.html
Recommended
Ranking