java - constructor calling in array creation -
int[] a=new int[4];
i think when array created ..there constructor calling (assigning elements default values) if correct..where constructor..
no, there no such thing. primitive array elements initialized default primitive value (0
int
). object array elements initialized null
.
you can use java.util.arrays.fill(array, defaultelementvalue)
fill array after create it.
to quote jls
an array created array creation expression (§15.10) or array initializer (§10.6).
if use initializer, values assigned. int[] ar = new int[] {1,2,3}
if using array creation expression (as in example), (jls):
each class variable, instance variable, or array component initialized default value when created
Comments
Post a Comment