J.VII · Java 25 practice question
What does the following Java 25 program print when no specific type pattern matches?
void main() {
Object o = true;
String kind = switch (o) {
case String s -> "string";
case Number n -> "number";
default -> "unknown";
};
System.out.println(kind);
}
Check answer and explanation
Correct answer: unknown
Explanation
`true` boxes to `Boolean`, which is neither a `String` nor a `Number`, so `default` runs and prints `unknown`.
Common trap
`Boolean` does not extend `Number` and is not a `String`.
Source: JEP 441: Pattern Matching for switch — Summary
Checked against the cited text on 2026-11-27.