Setting variables on Constructor VS on the class definition

后端 未结 2 1795
遥遥无期
遥遥无期 2020-12-03 14:42

Lately I\'ve been wondering if there\'s a difference between initializing the variables that have a default value on the Constructor VS on the class definition.

Whic

2条回答
  •  爱一瞬间的悲伤
    2020-12-03 15:28

    I think it mostly boils down to personal preferences. However, there are some values you can't set directly to the variable, such as new class instances, that you must assign in the constructor.

提交回复
热议问题