-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmulti_level_inheritance.py
126 lines (94 loc) · 2.49 KB
/
multi_level_inheritance.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
"""
Python OOP inheritance program
"""
class Person:
"""
Person class with name and email
"""
def __init__(self, name: str, age: int):
self._name = name
self._age = age
@property
def name(self) -> str:
"""Person name getter"""
return self._name
@name.setter
def name(self, name: str) -> None:
self._name = name
@property
def age(self) -> int:
"""Person name getter"""
return self._age
@age.setter
def age(self, age: int) -> None:
self._age = age
def __str__(self):
return f"Person Details: \nName: {self.name}\nAge: {self.age}"
class User(Person):
"""User class with email"""
def __init__(self, name: str, age: int, email: str):
super().__init__(name, age)
self._email = email
@property
def email(self) -> str:
"""email getter"""
return self._email
@email.setter
def email(self, email: str) -> None:
self._email = email
def __str__(self):
return f"""
User Details:
Name: {self.name}
Age: {self.age}
Email: {self.email}
"""
class Employee(User):
"""
Employee class with email and department
"""
def __init__(self, name: str, age: int, email: str, department: str, role: str):
super().__init__(name, age, email)
self._department = department
self._role = role
@property
def department(self) -> str:
"""department getter"""
return self._department
@department.setter
def department(self, department: str) -> None:
self._department = department
@property
def role(self) -> str:
"""
Employee role getter
"""
return self._role
@role.setter
def role(self, role) -> None:
self._role = role
def details(self) -> dict[str, str | int]:
"""Returns user details as a dictionary"""
return {
"name": self.name,
"age": self.age,
"email": self.email,
"department": self.department,
"role": self.role,
}
def __str__(self):
return f"""
Employee Details
Name: {self.name}
Age: {self.age}
Email: {self.email}
Department: {self.department}
Role: {self.role}
"""
person = Person("Sarmad", 19)
print(person)
user = User(person.name, person.age, "[email protected]")
print(user)
employee = Employee(user.name, user.age, user.email, "Engineering", "Software Engineer")
print(employee)
print(employee.details())