Multiple choice

What is the output of the given java code?

public class HelloWorld
{
public static void main(String []args)
{
int i;
switch(i) // Line 1
{
default : System.out.println("No Value");
case 0 : System.out.println("i is 0");
case 1 : System.out.println("i is 1");
}
}
}

  1. No Valuei is 0i is 1

  2. i is 0i is 1

  3. i is 1

  4. No output

  5. Compilation Error

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

This is the correct choice, we have declared the variable i, but we didn’t initialise it to any value. So, the compiler will raise an Error that “i has not been initialised”. So, this answer is correct.