Multiple choice

What is the output of the given java code?

public class HelloWorld
{
 public static
void main(String []args)
{
 int i=1;
 if(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");
 case 2 : System.out.
println("i is 2");
 }
 }

  1. Valuei is 0i is 1i is 2

  2. i is 0i is 1i is 2

  3. i is 1i is 2

  4. i is 2

  5. Compilation Error

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

This is the correct choice, there is an error in the code. We have declared variable i of integer type, and we are passing i into the if() statement.If() requires a Boolean type variable and we are passing an integer value to it. So the compiler will raise an error. So this answer is correct.