Multiple choice java

Which one is a valid declaration of a boolean?

  1. boolean b1 = 0;

  2. boolean b2 = 'false';

  3. boolean b3 = false;

  4. boolean b4 = Boolean.false();

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

A boolean can only be assigned the literal true or false.

AI explanation

In Java, boolean is a primitive type that only accepts the literal values true or false (not quoted, not numeric). 'boolean b3 = false;' is valid because false is the correct boolean literal. 'boolean b1 = 0;' fails because Java does not allow implicit conversion between int and boolean (unlike C/C++). 'boolean b2 = 'false';' fails because single quotes denote a char literal, and 'false' is a multi-character string, not a valid char, plus a char can't be assigned to boolean anyway. 'boolean b4 = Boolean.false();' is invalid because Boolean.false() isn't a method — false is a keyword/literal, not something invoked as a method call.