Discussion Forum : Data Types And Variables
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.

Was this answer helpful ?
Next Question
Submit Your Solution hear:

Your email address will not be published. Required fields are marked *