Java Exceptions

Here are 10 essential multiple-choice questions on Java Exceptions, covering key concepts.

Last Updated :
Discuss
Comments

Question 1

What is the difference between checked and unchecked exceptions?


  • Checked exceptions occur at runtime, unchecked exceptions occur at compile time


  • Checked exceptions must be handled or declared, unchecked exceptions don't require handling


  • Unchecked exceptions are caused by hardware failures, checked exceptions are not


  • Unchecked exceptions are always thrown by the JVM, checked exceptions are always user-define

Question 2

What is the output of the following code?

Java
public class Geeks {     public static void main(String[] args) {         try {             int result = 10 / 0;             System.out.println(result);         } catch (ArithmeticException e) {             System.out.println("Exception caught");         } finally {             System.out.println("Finally block executed");         }     } } 


  • Exception caught


  • Finally block executed

  • Exception caught Finally block executed

  • Compilation Error

Question 3

Which of the following statements is TRUE about the finally block?

  • It executes only if an exception occurs

  • It executes only if no exception occurs


  • It always executes, even if an exception occurs

  • It executes only if explicitly called

Question 4

What will happen if an exception occurs in a catch block?

  • The program terminates abruptly

  • The finally block executes, then the program terminates

  • The exception is ignored

  • Another catch block handles it automatically

Question 5

What exception is thrown if an invalid index is accessed in an array?

  • NullPointerException

  • IndexOutOfBoundsException

  • ArrayIndexOutOfBoundsException

  • IllegalArgumentException

Question 6

What will happen if no exception occurs in a try block?

  • The catch block executes

  • The finally block executes, but catch does not

  • Neither catch nor finally executes

  • The program terminates immediately

Question 7

Which keyword is used to declare that a method might throw an exception?

  • throw

  • try

  • throws

  • catch

Question 8

What will happen in the following code?

Java
public class Geeks {     public static void main(String[] args) {         try {             throw new NullPointerException("Demo");         } catch (ArithmeticException e) {             System.out.println("Arithmetic Exception");         } finally {             System.out.println("Finally block executed");         }     } } 


  • Arithmetic Exception Finally block executed

  • NullPointerException Finally block executed

  • Finally block executed

  • Compilation Error

Question 9

Which of the following can be thrown using the throw keyword?

  • Only checked exceptions

  • Only unchecked exceptions

  • Any instance of Throwable

  • Only RuntimeException and its subclasses

Question 10

Which block is used to handle exceptions in Java?

  • final

  • catch

  • throw

  • break

There are 10 questions to complete.

Take a part in the ongoing discussion