Below is a piece of code. I expect in the first print statement to print 456 but it is printing 123. Can anyone help with the explanation of this?
Have a look at the code below.
class employee():
__private_var = 123
phone_number=3274687
def __init__(self, phone):
self.phone_number = phone
# Private Functions
def get_private_func(self):
return self.__private_var
def set_private_func(self):
self.__private_var = 1
class VIP(employee):
phone_number=123456
__private_var = 456
obj1 = employee(1312321)
obj2 = VIP(1312321)
#Unable to reassign new value to private variable
print (obj2.get_private_func())
#Able to reassign new value to private variable
obj2.set_private_func()
print (obj2.get_private_func())
print (obj1.get_private_func())
Expected results:
456
1
123
Got these results:
123
1
123