File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Associate Certification (OCAJP 7/8) and the fly likes OCA Java Programmer 1 Guide CH 2 Question 8 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Associate Certification (OCAJP 7/8)
Bookmark "OCA Java Programmer 1 Guide CH 2 Question 8" Watch "OCA Java Programmer 1 Guide CH 2 Question 8" New topic
Author

OCA Java Programmer 1 Guide CH 2 Question 8

John Mercier
Greenhorn

Joined: Nov 23, 2006
Posts: 9

Which statements correctly declare boolean variables?

A. Boolean isValid = true;
B. boolean isValid = TRUE;
C. boolean isValid = new Boolean(true);
D. boolean isValid - 1;

The answers are A and C but I have a problem with A because it is a Boolean object not a native variable. I believe there should be a distinction because a Boolean can be null but a boolean cannot. Does this make sense or am I just wrong?
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5265
    
  13

A (boolean) primitive variable can never be null. Only object reference variables can be null.

The question itself asks for "boolean variables" not "boolean primitive variables". So I would say A and C are correct.


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OCA Java Programmer 1 Guide CH 2 Question 8