The question is Which four describe the correct default values for array elements of the types indicated? a)int =>0 b) String =>"null" c) Dog => null d)char =>'\u0000' e)float => 0.0f f) boolean => true The answers given are a,c,d,e I have a question regarding the option e) Arrays are always initialised with default values and float-point variables are defined as double by default..Is e) a right choice?
An array of floats can only hold float type compatible elements (double is larger). The default value of any element is of type float. Refer JLS:
4.5.1 Variables of Primitive Type A variable of a primitive type always holds a value of that exact primitive type.
4.5.3 Kinds of Variables Array components are unnamed variables that are created and initialized to default values (�4.5.5) whenever a new object that is an array is created (�15.10). The array components effectively cease to exist when the array is no longer referenced. See �10 for a description of arrays.
[ November 03, 2003: Message edited by: Vad Fogel ]
Arrays are always initialised with default values and float-point variables are defined as double by default..Is e) a right choice?[/QB]
I think what you are referring to is assigning a floating point literal to a variable. If you don't specify that is is a float by appending an 'f' it will be a double by default. When an array is initialized, however, if it is to contain floats, then the JVM will insert the default *float* value (not the default floating-point value).