-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest8.py
More file actions
52 lines (40 loc) · 1.12 KB
/
test8.py
File metadata and controls
52 lines (40 loc) · 1.12 KB
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
#!/usr/bin/python
# -*- coding: utf-8 -*-
class Employee:
empCount = 0
__e = 1
def __init__(self, name, salary):
self.name = name
self.salary = salary
Employee.empCount = Employee.empCount + 1
def displayCount(self):
print "total %d" % Employee.empCount
def displayEmployee(self):
print "name: ", self.name, ", salary: ", self.salary
e1 = Employee("aa", 1122)
print e1.empCount
print e1._Employee__e
class Parent:
def __init__(self):
print "调用父类的构造函数"
def parentMethod(self):
print "调用父类方法"
def setAttr(self, attr):
Parent.parentAttr = attr
self.pattr = attr
def getAttr(self):
print "父类属性:", Parent.parentAttr
print "父类属性1:", self.pattr
class Child(Parent, Employee):
def __init__(self):
print "调用子类构造函数"
#def parentMethod(self):
# print "调用子类'父类'方法"
def childMethod(self):
print "调用子类方法"
c = Child()
c.childMethod()
c.parentMethod()
c.setAttr(200)
c.getAttr()
c.displayCount()