-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOopsDemo.py
More file actions
31 lines (21 loc) · 780 Bytes
/
OopsDemo.py
File metadata and controls
31 lines (21 loc) · 780 Bytes
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
#self keyword is mandatory for calling variable names into method
#instance and class variables have whole different purpose
#constructor name should be __init__
#new keyword is not required when you create object
class Calculator:
num = 100 #class variables
#default constructor
def __init__(self, a, b):
self.firstNumber = a
self.secondNumber = b
print("I am called automatically when object is created")
def getData(self):
print("I am now executing as method in class")
def Summation(self):
return self.firstNumber + self.secondNumber + Calculator.num
obj = Calculator(2, 3)
obj.getData()
print(obj.Summation())
obj1 = Calculator(4, 5)
obj1.getData()
print(obj1.Summation())