Yes, finally block will be executed and it won't depend on any function or so.
Try to execute this code in your compiler:
Input:
public static void main(String[] args)
{
System.out.println(Test.test());
}
public static int test()
{
Try
{
return 0;
}
finally
{
System.out.println("xyz");
}
}
Hence it's proved from the example above.
The cases where finally won't work are:
- If JVM crashes first
- If System.exit() is invoked