Q54
What will be the output for the below code? public class Test public static void main(String[] args) byte i = 128; System.out.println(i);
A.
128
B.
0
C.
Compilation fails with an error at line 3
AnswerD.
Compilation fails with an error at line 4
E.
None of these
Answer: Option C
Solution
Answer: Option C
Solution:
byte can only hold up to 127. So compiler complain about possible loss of precision.static byte MAX_VALUE − This is constant holding the maximum value a byte can have, 27-1.
static byte MIN_VALUE − This is constant holding the minimum value a byte can have, -27.