AllInfoHub Logo

AllInfoHub – MCQ Practice

Exception Handling – Multiple Choice Questions (MCQs)

  1. 37. Can you have a `catch` block without a `try` block?

    • A. No
    • B. Yes
    • C. Only for unchecked exceptions
    • D. Only in specific scenarios
  2. 38. Can you have a `finally` block without a `try` block?

    • A. No
    • B. Yes
    • C. Only for cleanup operations
    • D. Only in specific scenarios
  3. 39. What is the try-with-resources" statement in Java (introduced in Java 7)?"

    • A. A simplified way to handle exceptions
    • B. A way to automatically manage resources that implement the `AutoCloseable` interface
    • C. A new type of exception handling block
    • D. A way to define custom resources
  4. 40. What interface must a resource implement to be used with the try-with-resources" statement?"

    • A. Closeable
    • B. AutoCloseable
    • C. Resource
    • D. Disposable
  5. 41. What is the advantage of using try-with-resources"?"

    • A. Manual resource closing is required
    • B. It ensures that resources are always closed
    • C. It only works for file I/O
    • D. It makes exception handling more complex