Pergunta de entrevista da empresa Penske Truck Leasing

Will a Java program reach the finally block if you return from the try block?

Respostas da entrevista

Sigiloso

13 de mar. de 2015

If finally wasn't called then it would be more apt to call the keyword 'perhaps' The only conditions for which it wouldn't be called are if the JVM crashes or if you call System.exit

Sigiloso

1 de jul. de 2013

Yes, the code in the finally block will still be executed. I guessed on this one as this isn't a scenario commonly seen in code (should be avoided, frankly) and I honestly couldn't remember. These are the kind of 'gotcha' textbook questions that test someone's memory more than their programming ability and should not be included in a professional interview.