What are arrays in Java? Do all array elements be initialized to default value?
Arrays are objects in Java. Array elements are just member variables of the class, and they are initialized to default value as any other class of objects.MyObject[] myobjarray; There is no array here, only an array reference type variable called myobjarray. If it is a field in another class, myobjarray will be initialized to null. If it is in a method, it will not be initialised. No exceptions here!!! MyObject[] myobjarray = new MyObject[5]; You are initializing myobjarray by constructing a MyObject[5] array, inside the new object instance of the MyObject[5] array, all fields will be initialized to default values, which are myobjarray[0] = null, myobjarray[1] = null, … and the length field would be initialized to 5. No exceptions here either!!!The only difference is that array classes do not have an known name. If you are really interested to know the class name of various arrays, you can see them here. It actually prints out some odd class names of arrays: TestRange.javaSee the bot