🎴 Flashcard Mode
Java and C Programming Fundamentals
Card1 / 20
Mastered0
Review0
QuestionClick to flip
package exceptions; public class TestException5 { static String trimString(String x) { return x.trim(); } public static void main(String[] args) { try { String s = trimString(null); System.out.println("s = "+s); } catch(Exception e) { System.out.println(" Exception "); } catch(NullPointerException ne) { System.out.println("Null Pointer Exception "); } } }
AnswerClick to flip back
A
Compiler Error
💡 Explanation:
This code produces a compiler error because the catch block order is invalid. Exception is a superclass of NullPointerException, so catching Exception first makes the NullPointerException catch unreachable. More specific exceptions must be caught before their parent types.