Java Exceptions Quiz(Beginner Level) total-qa June 13, 2025 June 13, 2025 No Comments on Java Exceptions Quiz(Beginner Level) 1. Which of the following is a checked exception? NullPointerException IOException ArithmeticException ArrayIndexOutOfBoundsException Explanation: Checked exceptions are checked at compile time, and IOException is a classic example. The others are unchecked (runtime) exceptions. 2. What happens if a method throws a checked exception but does not declare it in the method signature or handle it? Program compiles and runs normally Compile-time error occurs Runtime error occurs Exception is ignored Explanation: Java enforces handling of checked exceptions. If not caught or declared using throws, the compiler will throw an error. 3. Which of the following is a runtime exception? ClassNotFoundException NumberFormatException IOException FileNotFoundException Explanation: NumberFormatException are unchecked exceptions, so they occur at runtime. ClassNotFoundException, FileNotFoundException and IOException are checked exceptions. 4. Which keyword is used to manually throw an exception in Java? throw throws try catch Explanation: The throw keyword is used to explicitly throw an exception object. 5. What is the output of the following code? try { int a = 10 / 0; } catch (ArithmeticException e) { System.out.println("Exception caught"); } Compile-time error Runtime error Exception caught Program terminates silently Explanation: Division by zero throws an ArithmeticException, which is caught by the catch block. 6. What will happen if an exception is not caught? Code after the exception continues JVM will handle it and terminate the program Java automatically corrects the error The program restarts from main method Explanation: If uncaught, the JVM prints the stack trace and terminates the thread. 7. What is the output of this code? String s = null; System.out.println(s.length()); null Compilation error Runtime error: NullPointerException 0 Explanation: You’re trying to call a method (length()) on a null reference. 8. What is the output of this code? int x = Integer.parseInt("abc"); NumberFormatException IllegalArgumentException ArithmeticException ClassCastException Explanation: “abc” cannot be converted into a number. 9. What is the output of this code? try { int[] arr = new int[3]; System.out.println(arr[5]); } catch(Exception e) { System.out.println("Error occurred"); } 0 Error occurred 5 Compilation Error Explanation: Accessing arr[5] throws an ArrayIndexOutOfBoundsException, which is caught. 10. Which of the following is NOT a subclass of RuntimeException? NullPointerException IllegalArgumentException IOException ArithmeticException Explanation: IOException is a checked exception and is not part of the RuntimeException hierarchy. Loading …