Question -
What will be the output for the below code ? 1. public class Test{ 2. public static void main(String[] args){ 3. byte i = 128; 4. System.out.println(i); 5. } 6. }
Options:
A .  128
B .  0
C .  Compilation fails with an error at line 3
D .  Compilation fails with an error at line 4
E .  None of these
Answer: Option C 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.
Submit Your Solution hear: