This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Customer Requirements for Developers and have Marcho Behler on-line!
See this thread for details.
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


Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
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: 2591

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: null in a boolean?
 
It's not a secret anymore!