Home > Software design >  Why is the class variable's value being changed when I'm changing the value in an object (
Why is the class variable's value being changed when I'm changing the value in an object (

Time:11-15

code and output

The output should be 9 and 8 but I'm getting 9 and 9 which means the variable in the class is getting changed which shouldn't happen.

CodePudding user response:

Because you are referring to the same class with multiple handles; you have not created any new instances of the class.

Try adding print(rohan is harry) to your code, and then see how the outputs change if you add the () to the line rohan = Employee().

  • Related