Java Programming — Exception Handling
Java OOP, collections, multithreading
100 Questions 10 Topics Take Test
Advertisement
Showing 91–100 of 100 questions in Exception Handling
Q.91 Medium Exception Handling
Which of the following exceptions is a checked exception?
A ClassCastException
B FileNotFoundException
C StackOverflowError
D NullPointerException
Correct Answer:  B. FileNotFoundException
EXPLANATION

FileNotFoundException is a checked exception (extends IOException). Others are unchecked - ClassCastException and NullPointerException are RuntimeExceptions, StackOverflowError is an Error.

Take Test
Analyze the code:
try {
return 5;
} finally {
return 10;
}
What will be returned?
A 5
B 10
C Error
D Null
Correct Answer:  B. 10
EXPLANATION

The finally block always executes, and if it contains a return statement, it overrides the return value from try or catch block. So 10 is returned.

Take Test
Which exception is thrown when trying to access a method of a null object?
A NullAccessException
B NullPointerException
C NullReferenceException
D EmptyObjectException
Correct Answer:  B. NullPointerException
EXPLANATION

NullPointerException is thrown when attempting to call a method or access a property on a null object reference in Java.

Take Test
Q.94 Medium Exception Handling
What is the output of multiple catch blocks?
try {
int[] arr = {1, 2, 3};
System.out.println(arr[5]);
} catch(ArrayIndexOutOfBoundsException e) {
System.out.println("Index");
} catch(Exception e) {
System.out.println("Exception");
}
A Index
B Exception
C Both Index and Exception
D No output
Correct Answer:  A. Index
EXPLANATION

ArrayIndexOutOfBoundsException is thrown and caught by the first catch block. The second catch block is not executed. Only the most specific matching catch block executes.

Take Test
Which of the following is NOT a subclass of Throwable in Java?
A Error
B Exception
C RuntimeException
D Runnable
Correct Answer:  D. Runnable
EXPLANATION

Runnable is a functional interface, not related to exception hierarchy. Error and Exception are direct subclasses of Throwable. RuntimeException is a subclass of Exception.

Take Test
Advertisement
Q.96 Medium Exception Handling
What will be the output?
try {
throw new Exception("Test");
} catch(Exception e) {
System.out.println("Caught");
} finally {
System.out.println("Finally");
}
A Caught Finally
B Finally
C Caught
D Test Finally
Correct Answer:  A. Caught Finally
EXPLANATION

The exception is caught and prints "Caught". The finally block always executes after try-catch, printing "Finally". Output: Caught Finally

Take Test
Can you have a try block without a catch block in Java?
A No, catch block is mandatory
B Yes, if finally block is present
C Yes, if return statement is present
D No, you need at least one catch or finally
Correct Answer:  B. Yes, if finally block is present
EXPLANATION

A try block must be followed by either a catch block or a finally block (or both). A try block alone is not valid syntax.

Take Test
Which exception is thrown when a method receives an illegal or inappropriate argument?
A IllegalStateException
B IllegalArgumentException
C InvalidParameterException
D ParameterException
Correct Answer:  B. IllegalArgumentException
EXPLANATION

IllegalArgumentException is thrown to indicate that a method has been passed an illegal or inappropriate argument. It is an unchecked exception.

Take Test
Q.99 Medium Exception Handling
What is the output of the following code?
int x = 10;
try {
x = x / 0;
} catch(ArithmeticException e) {
x = x + 5;
} finally {
x = x * 2;
}
System.out.println(x);
A 10
B 30
C 20
D 40
Correct Answer:  B. 30
EXPLANATION

ArithmeticException is caught, x becomes 10+5=15. Finally block executes, x becomes 15*2=30. Finally block always executes regardless of exception.

Take Test
Which of the following is a checked exception in Java?
A NullPointerException
B IOException
C ArrayIndexOutOfBoundsException
D ArithmeticException
Correct Answer:  B. IOException
EXPLANATION

IOException is a checked exception that must be caught or declared in the method signature. NullPointerException, ArrayIndexOutOfBoundsException, and ArithmeticException are unchecked exceptions.

Take Test
IGET
iget AI
Online · Ask anything about exams
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips