🎴 Flashcard Mode

Java Programming Fundamentals

Card1 / 20
Mastered0
Review0
QuestionClick to flip

What is the output of the following code when compiled and run? Select one correct answer. public class Question02 { public static void main(String[] args){ int j = 017; int i = (byte)j >> 2; //line 1 System.out.println(Integer.toBinaryString(i)); //line 2 } }

AnswerClick to flip back
A
Prints 11
💡 Explanation:

017 is an octal literal in Java, equal to decimal 15. The (byte) cast doesn't change the value since 15 fits in a byte. Right-shifting 15 (binary 1111) by 2 positions gives 3 (binary 11). Integer.toBinaryString(3) outputs '11'.

Change Mode