100% Pass
What is the main purpose of exception handling in Java?
A) To ignore runtime errors
B) To stop the program immediately
✔✔C) To handle runtime errors gracefully
D) To avoid compilation errors
Which keyword is used to define a block of code that may throw an exception?
A) throw
B) catch
✔✔C) try
D) finally
Which of the following is a checked exception in Java?
✔✔A) IOException
B) ArithmeticException
C) NullPointerException
1
,D) ArrayIndexOutOfBoundsException
What happens if an exception is not caught in a Java program?
✔✔A) The program terminates abruptly
B) The exception is ignored
C) The program continues execution normally
D) The exception is automatically fixed
Which block of code is always executed in a try-catch-finally structure?
A) try
B) catch
✔✔C) finally
D) None of the above
What does the throw keyword do in Java?
A) Catches an exception
B) Suppresses an exception
✔✔C) Manually throws an exception
2
, D) Prevents exceptions from occurring
Which of the following exceptions is thrown when an object is accessed but is not initialized?
A) IOException
✔✔B) NullPointerException
C) ArrayIndexOutOfBoundsException
D) ArithmeticException
What is the correct way to define a custom exception in Java?
✔✔A) Extend the Exception class
B) Implement the Throwable interface
C) Override the catch block
D) Use the static keyword
Which of the following statements is true about the throws keyword?
✔✔A) It is used in method declarations to specify exceptions that may be thrown
B) It handles the exception inside a method
C) It is required for all exceptions
3