The finally block is the last bit of code executed before your program ends. True or False? Explain.
Single Choice
Views 39
Answer:
False.
The finally block is not always the last code executed before the program ends.
It executes after the try-catch block completes, regardless of whether an exception was thrown or not.
It is mainly used to release resources (like files or database connections) or perform cleanup tasks.
Example:
try { System.out.println("Inside try block"); } catch (Exception e) { System.out.println("Exception caught"); } finally { System.out.println("Finally block executed"); }
Related Articles:
This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.
Join Our telegram group to ask Questions
Click below button to join our groups.