Question 1
Which two statements about pattern matching for instanceof in Java 17 are correct? (Choose two.)
A. The pattern variable is in scope only where the compiler can prove the match succeeded, which can include an else branch or code after an early returnCorrect answer
JEP 394 uses flow scoping, so the binding exists exactly where definite-match analysis proves the pattern matched, which is why a negated test or an early return can place it in an else branch or in code after the if.
B. If the tested expression is null, the pattern matches and the variable is bound to null
instanceof is always false for null, with or without a pattern, so the variable is never bound to null.
C. A pattern variable is a non-final local variable, so code inside its scope may reassign itCorrect answer
The final design of JEP 394 made pattern variables ordinary non-final locals, so reassignment inside their scope is legal (though poor style).
D. Java 17 also allows type patterns as case labels in switch without any special compiler flags
Pattern matching for switch is only a preview in Java 17 (JEP 406), gated behind --enable-preview and outside 1Z0-829; only instanceof patterns are standard.
Explanation
Pattern matching for instanceof in Java 17 uses flow scoping, so a binding is visible exactly where definite-match analysis proves the match succeeded, and the variable it introduces is an ordinary non-final local. A null operand never matches a type pattern, so it yields false and binds nothing. Type patterns in switch remain a preview feature in Java 17 and are not part of the standard instanceof-only support.