File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

null in a boolean?

keerthidhar dongre

Joined: Jan 30, 2002
Posts: 26
public static void main(String args[])
Boolean a[]=new Boolean[4];
int I=1;
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,
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.
- Manish
keerthidhar dongre

Joined: Jan 30, 2002
Posts: 26
Thanks a lot Manish.
I agree. Here's the link:
subject: null in a boolean?
It's not a secret anymore!