Which of the following declaration are valid:
1. bool b = null; 2. boolean b = 1; 3. boolean b = true |false; 4. bool b = (10<11); 5. boolean b = true ||false;
Select 1 option
Correct Option is : D
bool is an invalid keyword.
Therefore, 1 and 4 can't be right.
boolean b = 1; is wrong because you can only assign true or false to a boolean variable.
1 is an integral value it cannot be converted to boolean.
boolean b = null; would be invalid as well because null is not a true or false value.
A primitive can never be assigned null.
boolean b = true |false; and boolean b = true ||false; are both valid.