Questions and Answers Already Passed
What happens if an exception occurs inside a try block without a corresponding catch block?
A) The program continues execution normally
✔✔B) The program terminates and displays an error message
C) The exception is ignored
D) The compiler fixes the issue automatically
Which of the following is a checked exception?
A) NullPointerException
B) ArithmeticException
✔✔C) IOException
D) IndexOutOfBoundsException
What is the purpose of the catch block?
A) It prevents exceptions from occurring
✔✔B) It handles exceptions that occur in the try block
C) It ensures code runs after an exception occurs
1
,D) It logs errors without stopping execution
Which keyword is used to define a method that might throw an exception?
A) try
✔✔B) throws
C) catch
D) finally
Which block is always executed regardless of whether an exception occurs?
A) catch
B) throw
✔✔C) finally
D) try
What type of exceptions are subclasses of RuntimeException?
✔✔A) Unchecked exceptions
B) Checked exceptions
C) Logical exceptions
2
, D) Declared exceptions
Which statement is true about the throw keyword?
A) It is used to catch exceptions
✔✔B) It is used to manually throw an exception
C) It defines a custom exception class
D) It prevents an exception from occurring
How can multiple exceptions be handled in Java?
✔✔A) By using multiple catch blocks
B) By defining multiple try blocks
C) By using nested finally blocks
D) By ignoring exceptions in code
What will happen if an exception is thrown but not caught?
✔✔A) The program will terminate abnormally
B) The exception will be ignored
C) The program will automatically fix the error
3