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 { case 1024 : System.out.
println("Hello"); case 1025 : System.out.
println("How r u?"); case 512 : System.out.
println("Bye"); case 513 : System.out.
println("Bye Bye"); default : System.out.
println("Good Bye");
 }
 }
 }

  1. HelloHow r u?Bye Bye ByeGood Bye

  2. How r u? Bye Bye Bye Good Bye

  3. Bye Bye ByeGood Bye

  4. Bye ByeGood Bye

  5. Good Bye

Reveal answer Fill a bubble to check yourself
E 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(i++), as we have used post-increment on Variable i, so the value of variable i is still -1024. So the switch statement becomes switch(-1024), but 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