Multiple choice

What is the output of the given java program?

public class HelloWorld
{
public static void main(String []args)
{
int i = 1024<<8<<3>>8>>3;
switch(i)
{
default : System.out.println("Default");
case 1048576/(34*32) : System.out.println("Case 1");
case 1073741824/(2*32*4*32*16*8) : System.out.println("Case 2");
case 1048576/(32*32) : System.out.println("Case 3");
}
}
}

  1. Default Case 1 Case 2 Case 3

  2. Case 1 Case 2 Case 3

  3. Case 2 Case 3

  4. Case 3

  5. Compiler Error

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

This is the correct choice because there is an error in the Program. Java doesn’t allow us to have Duplicate case labels in a Switch statement. In the given code, Case 2 and Case 3, both evaluate to the same value. So, when we try to compile the code, The compiler will raise an error, “duplicate case label”. So, this is the correct choice.