Overcoming rewriting and expansion

 1 class Animal:

2 def eat(self):
3 print("Eat")
4
5 def drink(self):
6 print("drink")
7
8 def run(self):
9 print("Run")
10
11 def sleep(self):
12 print("Sleep")
13
14 class Dog(Animal):
15 def bark(self):
16 print("Call")
17
18 class XiaoTianQuan(Dog):
19 def fly(self):
20 print("Fly")
21
22 # def bark(self):
23 # print("Called like a god")
24 #
25 # # Call the parent class bark method
26 # super().bark()
27 #
28 # # Extension
29 # print("[email Protected]$#@@(*U!(")
30
31 # Extension and rewrite of python2.x
32 def bark(self):
33
34 print("Call like a god")
35
36 Dog.bark(self)
37
38 print("@#[emailprotected]#[emailprotected]" )
39
40 xtq = XiaoTianQuan()
41 xtq.eat()
42 xtq.bark()
43 xtq.fly()

eat
Call like a god
Call
@#[email Protected]#[email Protected]
fly

 1 class Animal:

2 def eat(self):
3 print("Eat")
4
5 def drink(self):
6 print("drink")
7
8 def run(self):
9 print("Run")
10
11 def sleep(self):
12 print("Sleep")
13
14 class Dog(Animal):
15 def bark(self):
16 print("Call")
17
18 class XiaoTianQuan(Dog):
19 def fly(self):
20 print("Fly")
21
22 # def bark(self):
23 # print("Called like a god")
24 #
25 # # Call the parent class bark method
26 # super().bark()
27 #
28 # # Extension
29 # print("[email Protected]$#@@(*U!(")
30
31 # Extension and rewrite of python2.x
32 def bark(self):
33
34 print("Call like a god")
35
36 Dog.bark(self)
37
38 print("@#[emailprotected]#[emailprotected]" )
39
40 xtq = XiaoTianQuan()
41 xtq.eat()
42 xtq.bark()
43 xtq.fly()

eat
Call like a god
Call
@#[email Protected]#[email Protected]
fly

Leave a Comment

Your email address will not be published.