Which declaration initializes a boolean variable?

Which declaration initializes a boolean variable?

Which declaration initializes a boolean variable?

A.
boolean h = 1;

B.
boolean k = 0;

C.
boolean m = null;

D.
boolean j = (1 < 5) ;

Explanation:
The primitive type boolean has only two possible values: true and false. Here j is set to (1 <5), which evaluates to true.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


Jazz

Jazz

“D”

Boolean primitive type is only set to True/False, here (1<5) only returns True.

James

James

The Answer is D.

A Java boolean variable can only be true or false, nothing else. Uninitialized boolean instance variables of a class default to false.