Bird
0
0

Which of the following correctly demonstrates the placement of a finally block in a Java try-catch structure?

easy📝 Syntax Q3 of 15
Java - Exception Handling

Which of the following correctly demonstrates the placement of a finally block in a Java try-catch structure?

Atry { /* code */ } catch(Exception e) { /* handle */ } finally { /* cleanup */ }
Btry { /* code */ } finally { /* cleanup */ } catch(Exception e) { /* handle */ }
Ctry { /* code */ } catch(Exception e) { /* handle */ }
Dfinally { /* cleanup */ } try { /* code */ } catch(Exception e) { /* handle */ }
Step-by-Step Solution
Solution:
  1. Step 1: Understand try-catch-finally order

    The finally block must come after all catch blocks.
  2. Step 2: Analyze options

    try { /* code */ } catch(Exception e) { /* handle */ } finally { /* cleanup */ } correctly places finally after catch. try { /* code */ } finally { /* cleanup */ } catch(Exception e) { /* handle */ } places finally before catch, which is invalid. try { /* code */ } catch(Exception e) { /* handle */ } omits finally. finally { /* cleanup */ } try { /* code */ } catch(Exception e) { /* handle */ } places finally before try, which is invalid.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Correct order is try-catch-finally [OK]
Quick Trick: finally always follows catch blocks [OK]
Common Mistakes:
  • Placing finally before catch
  • Omitting finally block syntax
  • Putting finally before try block

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Java Quizzes