-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex45.py
61 lines (45 loc) · 934 Bytes
/
ex45.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
# -- coding: utf-8 --
#动物是物体
class Animal(object):
pass
#狗属于动物
class Dog(Animal):
def __init__(self, name):
self.name = name
#猫也属于动物
class Cat(Animal):
def __init__(self, name):
self.name = name
#人是物体的一种
class Person(object):
def __init__(self, name):
self.name = name
#人有一个宠物
self.pet = None
#有一种人叫做雇员
class Employee(Person):
def __init__(self, name, salary):
super(Employee, self).__init__(name)
self.salary = salary
#鱼也属于物体
class Fish(object):
pass
class Salmon(Fish):
pass
class Halibut(Fish):
pass
#rover是一只狗
rover = Dog("Rover")
#satan是一只猫
satan = Cat("Satan")
#Mary是一个人
mary = Person("Mary")
#satan是mary的
mary.pet = satan
#frank有120000的年薪
frank = Employee("Frank", 120000)
frank.pet = rover
flipper = Fish()
crouse = Salmon()
harry = Halibut()