Java OCA OCP Practice Question 349

Question

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

  • A. 1 and 4
  • B. 2, 3, and 5
  • C. 2 and 3
  • D. 3 and 5
  • E. 5


Correct Option is  : D

Note

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.




PreviousNext

Related