OCA Java SE 8 Operators/Statements - OCA Mock Question Operator and Statement 10


What data types will allow the following code snippet to compile? (Choose all that apply)

     byte x = 1; 
     byte y = 2; 
     _____ z = x + y; 
  1. int
  2. long
  3. boolean
  4. double
  5. short
  6. byte


A, B, D.


x and y are both type of byte.

x + y is automatically promoted to int.

int and data types that can be promoted automatically from int will make the code compile.

A, B, D are correct answers.

C is wrong since boolean is not a numeric data type.

E and F will work for a casting. They are smaller data type.