Java · Question 28 · Hard

What will be the output of the following Java program?

public class Main {
    public static void main(String[] args) {
        byte b = (byte) 200;
        System.out.println(b);
    }
}
  1. 56
  2. -200
  3. -56
  4. 200
Answer and explanation

Answer: C. -56

Explanation: A byte is 8-bit signed (-128 to 127). The cast keeps the low 8 bits of 200, which as a signed byte is 200 - 256 = -56.

Previous: What will be the output of the following Java program? · Next: What will be the output of the following Java program?

Practise java

Try a fresh set of java questions with an explanation after every answer, free and without signing up: Java practice. Or sit a full placement mock test.

More java questions

More technical & programming practice

Python · Data Structures · Algorithms · Object-Oriented Programming · DBMS · SQL · Operating Systems · Computer Networks

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge