This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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: 26

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
Sheriff

Joined: Jul 19, 2004
Posts: 7247
    
  29

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
OCAJP 7
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: OCA Java Programmer 1 Guide CH 2 Question 8
 
It's not a secret anymore!