Exception in Java MCQs Exercise I

Ques 1 Exception


Which keyword is used to declare an exception handler in Java?

A try
B catch
C handle
D throw

Ques 2 Exception


Which keyword is used to explicitly throw an exception in Java?

A try
B catch
C finally
D throw

Ques 3 Exception


What is the purpose of the "finally" block in Java exception handling?

A To handle exceptions that occur in the try block.
B To provide a place for code that always executes, whether an exception is thrown or not.
C To specify the type of exception to catch.
D To re-throw an exception that was caught earlier.

Ques 4 Exception


Which exception class is the superclass for all built-in exceptions in Java?

A Exception
B Throwable
C Error
D RuntimeException

Ques 5 Exception


Which of the following statements is true about checked exceptions in Java?

A Checked exceptions are subclasses of the RuntimeException class.
B Checked exceptions are also known as unchecked exceptions.
C Checked exceptions must be caught or declared using the "throws" keyword.
D Checked exceptions are automatically caught by the JVM.

Ques 6 Exception


What is the output of the following Java Code?

try {
    int result = 10 / 0;
    System.out.println(result);
} catch (ArithmeticException e) {
    System.out.println("Error: " + e.getMessage());
}

A Error: / by zero
B 0
C Compilation error
D ArithmeticException

Ques 7 Exception


What is the output of the following Java Code?

try {
    String str = null;
    System.out.println(str.length());
} catch (NullPointerException e) {
    System.out.println("NullPointerException: " + e.getMessage());
} catch (Exception e) {
    System.out.println("Exception: " + e.getMessage());
}

A Exception
B NullPointerException: null
C Compilation error
D NullPointerException