Multiple choice technology programming languages

you assign a value to the primitive variables x and y as indicated below. Which declaration for z must be used for this code to properly compile? byte x = 3; byte y = 2; // insert declaration for z here z = x + y;

    1. byte z;
    1. int z;
    1. char z
    1. None of these options are correct
Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

Arithmetic on byte, short, and char operands promotes to int. The expression x + y produces an int, which cannot be assigned to byte without an explicit cast. Therefore z must be declared as int to compile.