Skip to content

Commit 445ba9d

Browse files
authored
练习面向编程高级特性的多继承
1 parent 7666a9a commit 445ba9d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test23.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
'练习面向对象高级特性的多继承'
5+
6+
__author__ = 'sergiojune'
7+
8+
9+
class Animal(object):
10+
pass
11+
12+
13+
class Bird(Animal):
14+
pass
15+
16+
17+
class Mammal(Animal):
18+
pass
19+
20+
21+
# 加个扩展功能
22+
class Flyable(object):
23+
def fly(self):
24+
print('fly------------')
25+
26+
27+
class Runnable(object):
28+
def run(self):
29+
print('run-----------')
30+
31+
32+
# 这样就是多继承,加了和功能
33+
class Dog(Mammal, Runnable):
34+
pass
35+
36+
37+
# 多继承从做往右继承,在父类中有相同的方法时就会先实现左边的方法,就近原则
38+
class Parrot(Bird, Flyable):
39+
pass
40+

0 commit comments

Comments
 (0)