To determine the output of calling n2.calculate()
, we will look at the attributes of the n2
instance of the Addition
class.
The n2
object is created with the following parameters:
n2 = Addition(3000, 1000)
In the __init__
method, these values are assigned to self.first
and self.second
. Therefore:
self.first
= 3000self.second
= 1000
When the calculate
method is called on n2
, it performs the following steps:
-
It calculates the sum of
self.first
andself.second
:self.answer = self.first + self.second
This means:
self.answer = 3000 + 1000 = 4000
-
It then prints the result:
print("Addition of two numbers = " + str(self.answer))
This will output:
Addition of two numbers = 4000
Thus, the output of calling n2.calculate()
will be:
Addition of two numbers = 4000