public static void main(String[] args) {
 Integer i = new Integer(1) + new Integer(2);
 switch (i) {
  case 3:
   System.out.println("three");
   break;
  default:
   System.out.println("other");
   break;
 }
}

What is the output?

  1. three

  2. other

  3. Compilation Fails

  4. Exception


Correct Option: A

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) A. three - This option is correct because the value of i is 3 after adding 1 and 2 using the Integer class. The switch case matches with the value of i and prints "three" before the break statement.

Option B) B. other - This option is incorrect because the value of i is 3, which matches the case 3 in the switch statement. Therefore, "other" will not be printed.

Option C) C. Compilation Fails - This option is incorrect because there are no syntax errors in the code. The code will compile without any issues.

Option D) D. Exception - This option is incorrect because there are no exceptions thrown in the code. The code will run without any exceptions.

The correct answer is A. three. This option is correct because the value of i is 3 after adding 1 and 2 using the Integer class. The switch case matches with the value of i and prints "three" before the break statement.

Find more quizzes: