Java Interview Quiz - Why Doesn’t This Switch Compile?
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




