Submitted by Ashish.Hareet on Wed, 08/27/2008 - 16:24.
It depends on the context.
If we're talking about a member variable then the value will be false.
If we're talking about a local variable then the value needs to be explicitly initialized before being used.
The same holds for all other primitive & any reference data types. Reference data types will be initialized to null.
Do note that any final member variables will need to be initialized at the time of creation or in the constructor.
Try the following code sample
public class Test
{
static boolean b1;//try final here
static Object o1;//try final here
public static void main(String args[])
{
boolean b2;
Object o2;
System.out.println(b1);
System.out.println(o1);
//System.out.println(b2);//uncomment this line
//System.out.println(o2);//uncomment this line
}
}
The same holds for all other primitive & any reference data types. Reference data types will be initialized to null.
Do note that any final member variables will need to be initialized at the time of creation or in the constructor.
Try the following code sample
public class Test { static boolean b1;//try final here static Object o1;//try final here public static void main(String args[]) { boolean b2; Object o2; System.out.println(b1); System.out.println(o1); //System.out.println(b2);//uncomment this line //System.out.println(o2);//uncomment this line } }HTH
Ashish Hareet