Switch to Dark Mode

Java Exceptions

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

Last Updated : Apr 3, 2025
Discuss
Comments

Question 1

What is the difference between checked and unchecked exceptions?


  • A

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


  • B

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


  • C

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


  • D

    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");
        }
    }
}


  • A

    Exception caught


  • B

    Finally block executed

  • C

    Exception caught Finally block executed

  • D

    Compilation Error

Question 3

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

  • A

    It executes only if an exception occurs

  • B

    It executes only if no exception occurs


  • C

    It always executes, even if an exception occurs

  • D

    It executes only if explicitly called

Question 4

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

  • A

    The program terminates abruptly

  • B

    The finally block executes, then the program terminates

  • C

    The exception is ignored

  • D

    Another catch block handles it automatically

Question 5

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

  • A

    NullPointerException

  • B

    IndexOutOfBoundsException

  • C

    ArrayIndexOutOfBoundsException

  • D

    IllegalArgumentException

Question 6

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

  • A

    The catch block executes

  • B

    The finally block executes, but catch does not

  • C

    Neither catch nor finally executes

  • D

    The program terminates immediately

Question 7

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

  • A

    throw

  • B

    try

  • C

    throws

  • D

    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");
        }
    }
}


  • A

    Arithmetic Exception Finally block executed

  • B

    NullPointerException Finally block executed

  • C

    Finally block executed

  • D

    Compilation Error

Question 9

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

  • A

    Only checked exceptions

  • B

    Only unchecked exceptions

  • C

    Any instance of Throwable

  • D

    Only RuntimeException and its subclasses

Question 10

Which block is used to handle exceptions in Java?

  • A

    final

  • B

    catch

  • C

    throw

  • D

    break

There are 10 questions to complete.

Take a part in the ongoing discussion