Skip to content
Sharp

Language Upgrades · interview question

In Java, how does pattern matching for 'instanceof' improve code readability?

Multiple choiceEasychapter-12-curatedpremiumlanguage-upgradespattern-matching
Choose one answer
Answer and explanation

Correct answer

C. It eliminates explicit casting.

Why

Pattern matching for 'instanceof' allows you to declare and use a variable in the same expression, eliminating the need for an explicit cast after a type check.

Test yourself on Language Upgrades

A free test with instant, explained results. No account needed.

Start free test
All Language Upgrades questions →