s3a
December 9th, 2009, 03:06 AM
Based on what I know;
The default value for a (data field? - what is that exactly) of a boolean type, numeric type, object type is:
false, 0, and null respectively.
But for the numeric example why is the following variable x not initialized as 0?
public class Program
{
public static void main (String [] args)
{
double x; // If it was double x = 5; it would work
System.out.println(x);
}
}
Basically I am trying to answer the following practice test question:
"35. Which of the following statements are true?
A. local variables do not have default values.
B. data fields have default values.
C. A variable of a primitive type holds a value of the primitive type.
D. A variable of a reference type holds a reference to where an object is stored
in the memory.
E. You may assign an int value to a reference variable.
"
(Assuming I am right when I chose B for #34)
"34. The default value for data field of a boolean type, numeric type, object
, respectively.
type is
A. true, 1, Null
B. false, 0, null
C. true, 0, null
D. true, 1, null
E. false, 1, null"
Any help would be greatly appreciated!
Thanks in advance!
The default value for a (data field? - what is that exactly) of a boolean type, numeric type, object type is:
false, 0, and null respectively.
But for the numeric example why is the following variable x not initialized as 0?
public class Program
{
public static void main (String [] args)
{
double x; // If it was double x = 5; it would work
System.out.println(x);
}
}
Basically I am trying to answer the following practice test question:
"35. Which of the following statements are true?
A. local variables do not have default values.
B. data fields have default values.
C. A variable of a primitive type holds a value of the primitive type.
D. A variable of a reference type holds a reference to where an object is stored
in the memory.
E. You may assign an int value to a reference variable.
"
(Assuming I am right when I chose B for #34)
"34. The default value for data field of a boolean type, numeric type, object
, respectively.
type is
A. true, 1, Null
B. false, 0, null
C. true, 0, null
D. true, 1, null
E. false, 1, null"
Any help would be greatly appreciated!
Thanks in advance!