Multiple choice

What is the output of the given java program?

public class HelloWorld
{
public static void main(String []args)
{
int i = (1048576>>8>>3>>8>>3) + + - + (1024<<8<<3>>8>>3);
switch(i) // Line 1
{
default : System.out.println("Good Bye");
case 1024 : System.out.println(1024<<8<<3>>8>>3);
case 512 : System.out.println(1024<<2>>3<<2);
case 1 : System.out.println(1024<<3<<8>>3>>3);
}
}
}

  1. Good Bye 1024 2048 32768

  2. 1024 2048 32768

  3. 2048 32768

  4. 32768

  5. Compilation error

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

This is the correct choice, the value of variable i after evaluating the expression (1048576>>8>>3>>8>>3) + + - + (1024<<8<<3>>8>>3) comes out to be -1024.The expression is evaluated as following :-(1024*(2^8)(2^3)) / ((2^8)/(2^3)) - (1024(2^8)*(2^3)) / ((2^8)/(2^3)) = -1024. So, the switch statement becomes switch(-1024), bu there is no case label having label -1024, so the default case will be executed until a break keyword is found.So the output is: Good Bye 1024 2048 32768.So this answer is true.