|
发表于 2017-4-17 10:44:12
|
显示全部楼层
-------------------------------------
本帖最后由 MichaelFMM 于 2017-4-17 10:57 编辑
# coding=utf-8
class Employee(object):
"""docstring for Employee"""
count = 0
def __init__(self, name):
# super(Employee, self).__init__()
self.name = name
# def __del__(self):
# print 'Delete Done!'
# def getCompanyTotalEmployee(self, intEmployee):
# return intEmployee
class Management(Employee):
"""docstring for Management"""
def __init__(self, name):
# super(Management, self).__init__()
self.name = name
print '新增管理人员:', self.name
self.count = self.count + 1
print '新增实例化后,管理层人数:', self.count
def getSalary(self, intSalary):
return intSalary
def __del__(self):
print 'Management Delete Done!'
self.count = self.count - 1
print '删除实例后,管理层人数:', self.count
class Staff(Employee):
"""docstring for Staff"""
def __init__(self, name):
# super(Management, self).__init__()
self.name = name
print '新增员工:', self.name
self.count = self.count + 1
print '新增实例化后,员工人数:', self.count
def getCredits(self, intCredits):
return intCredits
def __del__(self):
print 'Management Delete Done!'
self.count = self.count - 1
print '删除实例后员工人数:', self.count
if __name__ == '__main__':
m = Management('Mic')
print m.name, '管理人员工资:', m.getSalary(999999)
print 'm.count: ', m.count
s = Staff('dddbbb')
print s.name, '员工积分', s.getCredits(11111)
print 's.count: ', s.count
运行结果:-------------------------------------------------------------------
新增管理人员: Mic
新增实例化后,管理层人数: 1
Mic 管理人员工资: 999999
m.count: 1
新增员工: dddbbb
新增实例化后,员工人数: 1
dddbbb 员工积分 11111
s.count: 1
Management Delete Done!
删除实例后,管理层人数: 0
Management Delete Done!
删除实例后员工人数: 0
***Repl Closed***
|
|