Did I understand correctly that if a class has an instance variable (for example, int x = 7;), then when creating an object of this class, this variable contains that value defined in the class. For example, if we create an object and then change the value of a variable (for example, by 5) with the help of a link (or a constructor), then after creating another object, it will contain the old value (that is, 7).
|
1 answer
Yes, you understood correctly. If you set an initial value of 7 for a variable, then each new instance of the class will name the value of a variable 7. But this value can be changed. And you can initialize a variable with a necessary value when creating an object in the constructor.
- Thank you very much. - Max
|