How many finally{} blocks may there be in a try/catch structure?
-
There must always be one, following the last catch{} block.
-
There can be zero or one immediately after each catch{} block.
-
There can be zero or one, following the last catch{} block.
-
There can be any number, following the last catch{} block.
In try/catch/finally structure, there can be at most ONE finally block, and if present, it must appear AFTER the last catch block. The finally block is optional (can be zero), but if used, only one is allowed per try-catch structure. Option C correctly states: there can be zero or one, following the last catch block.
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.