Skip to content

Commit d23c7de

Browse files
committed
Object Creation added
1 parent 573831b commit d23c7de

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

Object Creation.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
class Car_Wheel:
2+
total_wheels = 0
3+
def __new__(self, value):
4+
# new method is called first for object creation
5+
if Car_Wheel.total_wheels < 5:
6+
Car_Wheel.total_wheels += 1
7+
return super().__new__(self)
8+
else:
9+
raise Exception('Only five car wheels are allowed!!')
10+
11+
def __init__(self, side):
12+
# Initiliazer is called for initializing values
13+
self.side = side
14+
print(f"{self.side} created")
15+
16+
17+
if __name__ == '__main__':
18+
wheel_01 = Car_Wheel('Front Left')
19+
wheel_02 = Car_Wheel('Front Right')
20+
wheel_03 = Car_Wheel('Rear Left')
21+
wheel_04 = Car_Wheel('Rear Right')
22+
wheel_05 = Car_Wheel('Puncture wheel')
23+
24+
try:
25+
print('Trying creating extra wheel')
26+
wheel_06 = Car_Wheel('No side')
27+
except Exception as msg:
28+
print(msg)
29+
30+
31+

0 commit comments

Comments
 (0)