In Java, does the finally block get executed if we insert a return statement inside the try block of a try-catch-finally?
Yes, it will get executed. The finally block gets executed when the try block exists. Even when we attempt to exit within the try block(via a return statement, a continue statement, a break statement or any exception), the finally block will still be executed.
Note that there are some cases in which the finally block will not get executed, such as the following:
1. If the virtual machine exits during try/catch block execution.
2.If the thread which is executing the try/catch block gets killed.