Question d’entretien chez Penske Truck Leasing

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

Réponses aux questions d'entretien

Utilisateur anonyme

13 mars 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

Utilisateur anonyme

1 juil. 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.