Interview question: Does a System.exit() in a try block execute code in following finally block?
public class Finally {
public static void main(String[] args)
{
try
{
System.out.println("The try block is executed");
System.exit(0);
}
finally
{
System.out.println("The finally block is executed");
}
}
}
The answer: No, code in the finally block will not execute if there is a System.exit() call within the try block.