Exceptions Questions and Answers

Practice Mode
Showing 10 of 30 questions
Q11
Which of these is a checked exception in Java?
  • A RuntimeException
  • B IOException
  • C NullPointerException
  • D ArithmeticException
Answer: Option B
Explanation: Checked exceptions must be handled at compile time.
Q12
What is the parent class of all exceptions in Java?
  • A Throwable
  • B Exception
  • C Error
  • D Object
Answer: Option A
Explanation: Throwable is the superclass of all errors and exceptions.
Q13
Which keyword is used to explicitly throw an exception?
  • A throws
  • B throw
  • C try
  • D catch
Answer: Option B
Explanation: The throw keyword is used to manually throw exceptions.
Q14
Which block is used to handle exceptions in Java?
  • A try-catch
  • B throw-catch
  • C exception-handle
  • D error-handle
Answer: Option A
Explanation: try-catch blocks are used for exception handling.
Q15
Which block is always executed regardless of whether an exception occurs or not?
  • A finally
  • B catch
  • C throw
  • D throws
Answer: Option A
Explanation: finally block always executes after try-catch.
Q16
What is the output when a NullPointerException occurs?
  • A Runtime exception when using null object reference
  • B Compile time error
  • C Warning message
  • D No output
Answer: Option A
Explanation: NullPointerException occurs when using null objects.
Q17
Which of these exceptions is related to array operations?
  • A ArrayIndexOutOfBoundsException
  • B NullPointerException
  • C ClassCastException
  • D IOException
Answer: Option A
Explanation: ArrayIndexOutOfBoundsException occurs with invalid array indices.
Q18
What does the try-with-resources statement ensure?
  • A Automatic resource closure
  • B Manual resource management
  • C Exception suppression
  • D No exception handling
Answer: Option A
Explanation: try-with-resources automatically closes resources.
Q19
Which exception occurs when converting invalid string to number?
  • A NumberFormatException
  • B IllegalArgumentException
  • C ParseException
  • D FormatException
Answer: Option A
Explanation: NumberFormatException occurs during invalid number conversion.
Q20
What is the purpose of the throws keyword?
  • A Declare exceptions in method signature
  • B Throw an exception
  • C Catch an exception
  • D Handle an exception
Answer: Option A
Explanation: throws declares exceptions that a method might throw.
Questions and Answers for Competitive Exams Various Entrance Test