Question 56Asked in DSSSB TGT Computer Science (Technical), 1 Aug 2021, Shift 3

What is the output of the given java code? byte x = 64, y;

What is the output of the given java code? byte x = 64, y; y = (byte) (x << 4); system.out.println(y);
  1. A0
  2. B128
  3. C256
  4. D32
Show answerHide answer

Correct answer: (A) 0

Explanation

x << 4 is 64 × 16 = 1024 = 0x400 (as int). Casting to byte keeps only the low 8 bits, 0x00, so y prints 0.

From DSSSB TGT Computer Science PYQ (Technical), 1 Aug 2021, Shift 3

This is question 56 of DSSSB TGT Computer Science PYQ (Technical), 1 Aug 2021, Shift 3. See all questions of this paper with answers, or attempt the paper as a timed online test to get your score and all-India rank.