ExamVeda
Login
Home
Data Types and Variables
?

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);
      }
}

Answer & Solution
Correct 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.
Examveda
Question posted by Examveda
Community

Join the Discussion

5 Comments
Mallikarjun Guggari
Mallikarjun Guggari 3 years ago
the range of the byte is -128 to 127 if above 127 is their means it give error so plz first check the range of the byte before going to nxt line if the range is above 127 then it give error if u want an output then give the explicit type convertion to that like as
byte i = (byte)128;
system.out println(b);
output : -128
Examveda
Examveda 9 years ago
It cannot converted to 0. since its range is -128 to 127
Padmavathi Vaka
Padmavathi Vaka 9 years ago
Plz reply
Padmavathi Vaka
Padmavathi Vaka 9 years ago
Why it is not converting to 0
Ankita Maurya
Ankita Maurya 10 years ago
But, why can,t hold byte this no. 128.
plz.... reply