-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinheritanceCreateSubclass.py
More file actions
67 lines (44 loc) · 1.48 KB
/
inheritanceCreateSubclass.py
File metadata and controls
67 lines (44 loc) · 1.48 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Ineritance Creating Subclass
class Employee:
no_of_emp = 0
raise_amount = 1.04
def __init__(self, first, last, pay):
self.first = first
self.last = last
self.pay = pay
self.email = first + "." + last + "@gmail.com"
Employee.no_of_emp += 1
def apply_raise(self):
self.pay = int(self.pay * self.raise_amount)
def fullname(self):
return '{} {}'.format(self.first, self.last)
class Developer(Employee):
raise_amount =1.10
def __init__(self, first, last, pay, prog_lang):
super().__init__(first,last,pay)
self.prog_lang = prog_lang
class Manager(Employee):
def __init__(self, first, last, pay, employees=None):
super().__init__(first, last, pay)
if employees is None:
self.employees = []
else:
self.employees = employees
def add_emp(self, emp):
if emp not in self.employees:
self.employees.append(emp)
def remove_emp(self, emp):
if emp in self.employees:
self.employees.remove(emp)
def print_emp(self):
for emp in self.employees:
print('-->', emp.fullname())
dev_1 = Developer('Subhash','Y', 50000,'Python')
dev_2 = Developer('Princ','Kumar',60000,'JavaScript')
mgr_1 = Manager('Sue', 'Smith', 90000, [dev_1])
print(mgr_1.email)
mgr_1.add_emp(dev_2)
mgr_1.print_emp()
# two intresting Methods issubclass() and isinstance()
# print(dev_1.email)
# print(dev_1.prog_lang)