Which of the following statements about a finally block is true?
A. Every line of the finally block is guaranteed to be executed.
B. The finally block is executed only if the related catch block is also executed.
C. The finally block is called regardless of whether or not the related catch block is executed
D. The finally block cannot throw an exception
Answer:
C. The finally block is called regardless of whether or not the related catch block is executed
Explanation:
The finally block can throw an exception, in which case not every line of the finally block would be executed. For this reason, Options A and D are incorrect. Option B is also incorrect.
The finally block is called regardless of whether or not the related catch block is executed. Option C is the correct answer. Unlike an if-then statement, which can take a single statement, a finally statement requires brackets {}.
Free Spring Boot Tutorial - 5 Hours Full Course
Watch this course on YouTube at Spring Boot Tutorial | Fee 5 Hours Full Course