java - 既然有参构造方法中,参数可以通过new 赋值,为什么还要通过参数赋值给未初始化的成员变量来输出结果?
PHP中文网
PHP中文网 2017-04-18 10:50:06
0
2
587

PHP中文网
PHP中文网

认证高级PHP讲师

reply all(2)
大家讲道理

You are probably talking about assigning values ​​directly when writing fields. This is similar to assigning a value in the constructor. However, writing it directly on the field is generally regarded as the default value. If you need to pass in different values ​​​​according to the situation, you need a constructor.

PHPzhong

If you have multiple constructors, and some constructors do not initialize some member variables, then the remaining member variables do not have default values ​​set, something may go wrong

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template