Given the following code snippet inside a method: try { // risky code } catch (IOException | SQLException e) { // handle } What is the implicit type of the exception variable 'e' in the catch block?
The common base of IOException and SQLException is Exception.
Why this answer
In Java, when a multi-catch clause catches multiple exception types (e.g., IOException | SQLException), the compiler infers the catch parameter's type as the closest common superclass that is not Object or Throwable. Since IOException and SQLException both extend Exception directly, the implicit type of 'e' is Exception. This allows the catch block to handle both exception types polymorphically.
Exam trap
The trap here is that candidates mistakenly think 'e' has a union type (like TypeScript) or that the compiler uses the first listed exception type, when in fact Java infers the most specific common superclass, which is Exception for IOException and SQLException.
How to eliminate wrong answers
Option A is wrong because the implicit type is not Object; the compiler selects the most specific common superclass, which is Exception, not Object. Option C is wrong because Throwable is too broad; the common superclass of IOException and SQLException is Exception, not Throwable. Option D is wrong because 'e' is not a union type; it is a single type (Exception) that can reference either IOException or SQLException at runtime, but its compile-time type is Exception.