27.10.2014 Views

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

Cracking the Coding Interview, 4 Edition - 150 Programming Interview Questions and Solutions

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Solutions</strong> to Chapter 14 | Java<br />

14.2 In Java, does <strong>the</strong> finally block gets executed if we insert a return statement inside <strong>the</strong><br />

try block of a try-catch-finally?<br />

SOLUTION<br />

pg 78<br />

Yes, it will get executed.<br />

The finally block gets executed when <strong>the</strong> try block exists. However, even when we attempt<br />

to exit within <strong>the</strong> try block (normal exit, return, continue, break or any exception), <strong>the</strong> finally<br />

block will still be executed.<br />

Note: There are some cases in which <strong>the</strong> finally block will not get executed: if <strong>the</strong><br />

virtual machine exits in between try/catch block execution, or <strong>the</strong> thread which<br />

is executing try/catch block gets killed.<br />

CareerCup.com<br />

2 2 6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!