aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B book chapter 1 Q.No.15 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B book chapter 1 Q.No.15" Watch "K&B book chapter 1 Q.No.15" New topic
Author

K&B book chapter 1 Q.No.15

Lakshmi Saradha
Ranch Hand

Joined: Oct 21, 2003
Posts: 170
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?


Thanks,<br />Lakshmi.
Vad Fogel
Ranch Hand

Joined: Aug 25, 2003
Posts: 504
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 ]
Derek Baker
Ranch Hand

Joined: May 23, 2003
Posts: 46
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).
Lakshmi Saradha
Ranch Hand

Joined: Oct 21, 2003
Posts: 170
thank you..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B book chapter 1 Q.No.15