Java Programming Multiple Choice Questions - Exception Handling
This section focuses on the "Exception Handling" In Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.
1. Which statement is true?
A. catch(X x) can catch subclasses of X where X is a subclass of Exception.
B. Any statement that can throw an Exception must be enclosed in a try block.
C. The Error class is a RuntimeException.
D. Any statement that can throw an Error must be enclosed in a try block.
View Answer
Ans : A
Explanation: Option A is correct. If the class specified in the catch clause does have subclasses, any exception object that subclasses the specified class will be caught as well.
Option B is wrong. The error class is a subclass of Throwable and not Runtime Exception.
Option C is wrong. You do not catch this class of error.
Option D is wrong. An exception can be thrown to the next method higher up the call stack.
2. Which statement is true?
A. An Error that might be thrown in a method must be declared as thrown by that method, or be handled within that method.
B. Multiple catch statements can catch the same class of exception more than once.
C. A try statement must have at least one corresponding catch block.
D. Except in case of VM shutdown, if a try block starts to execute, a corresponding finally block will always start to execute.
View Answer
Ans : D
Explanation: A is wrong. A try statement can exist without catch, but it must have a finally statement.
B is wrong. A try statement executes a block. If a value is thrown and the try statement has one or more catch clauses that can catch it, then control will be transferred to the first such catch clause. If that catch block completes normally, then the try statement completes normally.
C is wrong. Exceptions of type Error and RuntimeException do not have to be caught, only checked exceptions (java.lan
3. When does Exceptions in Java arises in code sequence?
A. Run Time
B. Can Occur Any Time
C. Compilation Time
D. None of the mentioned
View Answer
Ans : A
Explanation: Exceptions in Java are run-time errors.
4. Which of these keywords is not a part of exception handling?
A. finally
B. thrown
C. catch
D. try
View Answer
Ans : B
Explanation: Exceptional handling is managed via 5 keywords – try, catch, throws, throw and finally.
5. Which of these keywords must be used to monitor for exceptions?
A. finally
B. throw
C. catch
D. try
View Answer
Ans : D
Explanation: Try keywords must be used to monitor for exceptions
6. Which of these keywords must be used to handle the exception thrown by try block in some rational manner?
A. finally
B. throw
C. catch
D. try
View Answer
Ans : C
Explanation: If an exception occurs within the try block, it is thrown and cached by catch block for processing.
7. Which of these keywords is used to manually throw an exception?
A. finally
B. throw
C. catch
D. try
View Answer
Ans : B
Explanation: Throw keywords is used to manually throw an exception.
8. Which of these is a super class of all errors and exceptions in the Java language?
A. Catchable
B. Throwable
C. RunTimeExceptions
D. None of the above
View Answer
Ans : B
Explanation: Throwable is a super class of all errors and exceptions in the Java language
9. In which of the following package Exception class exist?
A. java.file
B. java.lang
C. java.io
D. java.util
View Answer
Ans : B
Explanation: No explanation.
10. Which exception is thrown when divide by zero statement executes?
A. NumberFormatException
B. NullPointerException
C. ArithmeticException
D. None of these
View Answer
Ans : C
Explanation: ArithmeticException is thrown when divide by zero statement executes.
Also check :
Discussion