Engineering With Java

Engineering With Java

Java Interview Quiz - Why Doesn’t This Switch Compile?

Suraj Mishra's avatar
Suraj Mishra
Dec 10, 2025
∙ Paid

The following Java code fails to compile. Why?

A. Because sealed interfaces cannot be used in switch statements.

B. Because the switch must handle all concrete permitted subclasses of Event, but Error is abstract and cannot be the only case.

C. Because Error is sealed, so you must use a default case.

D. Because switch expressions cannot return Strings.


📢 Consider becoming a paid subscriber for as low as $2.5/mo (with an annual subscription) and support the work :)

Not convinced? Check out the details of the past work


Correct Answer: B

Explanation

User's avatar

Continue reading this post for free, courtesy of Suraj Mishra.

Or purchase a paid subscription.
© 2025 Suraj Mishra · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture