Page 1 of 1
About Question enthuware.ocpjp.v21.2.4038 :
Posted: Sat Jun 14, 2025 4:24 am
by nkaragulov
Does it mean constructor is allowed to change the value of the fields?
I checked it and confirm that it is indeed.
Re: About Question enthuware.ocpjp.v21.2.4038 :
Posted: Sat Jun 14, 2025 9:39 am
by admin
No, nobody can change the value of the fields of a record. See this part of the explanation:
Remember that at the end of the compact record constructor, the compiler adds code that sets all the fields to the values passed in the constructor. So, if the constructor changes the passed value (as is being done in the case of the subjects variable), the updated value will be given to the subjects field of the record instance.
So, the constructor is not really changing the value of the fields. It is changing the value of the input parameters.
Re: About Question enthuware.ocpjp.v21.2.4038 :
Posted: Sat Jun 14, 2025 10:36 am
by nkaragulov
admin wrote: ↑Sat Jun 14, 2025 9:39 am
No, nobody can change the value of the fields of a record. See this part of the explanation:
Remember that at the end of the compact record constructor, the compiler adds code that sets all the fields to the values passed in the constructor. So, if the constructor changes the passed value (as is being done in the case of the subjects variable), the updated value will be given to the subjects field of the record instance.
So, the constructor is not really changing the value of the fields. It is changing the value of the input parameters.
and it follows that those parameter values are set to fields at the end. seems now I get it. thanks!