In the proposed solution, the properties seem to be created as Class Variables (i.e. outside the initializer).
In my understanding, those variables are expected to be shared between all Student Class’s instances.
Right?
But the following code works as expected (each Student’s instance has it own __name
property properly set)
student1 = Student()
student1.setName("Alex")
student2 = Student()
student2.setName("John")
print("Student1 name: ", student1.getName())
print("Student2 name: ", student2.getName())
Output:
Student1 name: Alex
Student2 name: John
Did I misunderstand something?
Why the Class Variables are not shared by instances in this cases?