Java OCA OCP Practice Question 634

Question

Which of the following is illegal ?

Select 1 option

  • A. char c = 320;
  • B. float f = 320;
  • C. double d = 320;
  • D. byte b = 320;
  • E. None of the above is illegal.


Correct Option is  : D

Note

A. is wrong.

This is valid because 320 is below the maximum value that a char can take, which is 2^16 - 1. Remember that char can take only positive values.

B. is wrong.

320 is an int and so can be assigned to an int variable.

f = 320.0 is not valid as 320.0 would be a double.

C. is wrong.

This is valid because an int can be assigned to a double without any cast.

D. is wrong.

320 cannot fit into a byte so you must cast it.: byte b = (byte) 320;




PreviousNext

Related