java变量的默认值有什么用?所有变量在用的时候既然都要初始化,那默认值有什么用?
巴扎黑
巴扎黑 2017-04-18 10:44:47
0
4
560
巴扎黑
巴扎黑

reply all(4)
黄舟

In fact, only basic types have default values, mainly to prevent null pointer exceptions. User-defined types need to be initialized by the user

伊谢尔伦

Only class variables have default values ​​and do not need to be initialized manually

阿神

When we create a new object, Java will apply for a memory area in Heap to store the class data. The member variables are the data of the class and are also placed in this memory area. When we do not initialize the variable, the data in the Heap has no reference. At this time, if this variable is used elsewhere in the program, a null pointer exception will be thrown!

黄舟

Maybe he needs a clean object. Wiping it clean every time is very tiring. . . (nonsense)

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