Multiple choice technology programming languages

package testswitch; public class TestSwitch3 { public static void main(String[] args) { long p = 10; final long q = 100; switch (p) { case q: System.out.println("in q"); break; case 10: System.out.println("in 10"); break; default: System.out.println("default"); } } }

  1. in 10 Default

  2. Compiler error

  3. in 10

  4. Exception

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

The switch statement in Java does not support the long type as the expression variable. Switch expressions can only be int, short, char, byte (and their wrapper classes), String (Java 7+), or enum types. Since p is a long, this code will not compile regardless of the case labels used.

AI explanation

Java's switch statement only supports byte, short, char, int (and their wrapper types), String, and enum types as the switch expression — it does not support long. Since p is declared as a long, switch(p) fails to compile regardless of what the case labels are, which is why the correct result is a compiler error rather than any printed output.