Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OCA Java Programmer 1 Guide CH 2 Question 8

 
John Mercier
Greenhorn
Posts: 26
Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9790
101
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic