File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes null in a boolean? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "null in a boolean?" Watch "null in a boolean?" New topic
Author

null in a boolean?

keerthidhar dongre
Greenhorn

Joined: Jan 30, 2002
Posts: 26
public static void main(String args[])
{
Boolean a[]=new Boolean[4];
int I=1;
System.out.println(a[I]);
}
Why does this print null? when the only values a boolean can hold are true and false? Also why does this compile since the array elements are not initialized?
Thanks in advance,
Keerthi
Manish Hatwalne
Ranch Hand

Joined: Sep 22, 2001
Posts: 2579

Boolean is a wrapper class and boolean is primitive which can hold only true or false. What you have is an array of 4 Boolean type object references.
Arrays are always initialized, even if they are local to the method.
HTH,
- Manish
keerthidhar dongre
Greenhorn

Joined: Jan 30, 2002
Posts: 26
Thanks a lot Manish.
 
jQuery in Action, 2nd edition
 
subject: null in a boolean?