Machine-translated by Google. Questions are authored in English.
Top

Discussion

Which one is a valid declaration of a boolean?

  • A.boolean b1 = 0;
  • B.boolean b2 = 'false';
  • C.boolean b3 = false;
  • D.boolean b4 = Boolean.false();
  • E.boolean b5 = no;

Answer: C

Correct answer: boolean b3 = false;

A boolean accepts only the literals true and false. Java performs no conversion between numbers and booleans, so 0 is not accepted - the C idiom of zero meaning false does not carry over. 'false' in single quotes is a char literal and in any case too long to be one, Boolean.false() is not a method, and no is an undeclared identifier.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.