Java OCA OCP Practice Question 568

Question

What data type or types will allow the following code snippet to compile?

Choose all that apply

byte x = 5; 
byte y = 10; 
_____ z = x + y; 
  • A. int
  • B. long
  • C. boolean
  • D. double
  • E. short
  • F. byte


A, B, D.

Note

The value x + y is automatically promoted to int, so int and data types that can be promoted automatically from int will work.

Options A, B, D are such data types.

Option C will not work because boolean is not a numeric data type.

Options E and F will not work without an explicit cast to a smaller data type.




PreviousNext

Related