How many finally{} blocks may there be in a try/catch structure?

  1. There must always be one, following the last catch{} block.

  2. There can be zero or one immediately after each catch{} block.

  3. There can be zero or one, following the last catch{} block.

  4. There can be any number, following the last catch{} block.


Correct Option: C

AI Explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) There must always be one, following the last catch{} block. This option is incorrect. There is no requirement for a finally{} block to follow the last catch{} block. It is optional.

Option B) There can be zero or one immediately after each catch{} block. This option is incorrect. While it is true that there can be zero or one finally{} block immediately after each catch{} block, the question specifically asks about the number of finally{} blocks following the last catch{} block.

Option C) There can be zero or one, following the last catch{} block. This option is correct. The correct answer is C. After the last catch{} block, there can be zero or one finally{} block. It is not required to have a finally{} block following the last catch{} block.

Option D) There can be any number, following the last catch{} block. This option is incorrect. The number of finally{} blocks following the last catch{} block is limited to zero or one, as stated in option C.

Therefore, the correct answer is C. There can be zero or one finally{} block following the last catch{} block.

Find more quizzes: