25.03.2013 Views

Cracking the Coding Interview - Fooo

Cracking the Coding Interview - Fooo

Cracking the Coding Interview - Fooo

SHOW MORE
SHOW LESS

Create successful ePaper yourself

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

Solutions to Chapter 14 | Java<br />

14 3 What is <strong>the</strong> difference between final, finally, and finalize?<br />

SOLUTIONS<br />

Final<br />

When applied to a variable (primitive): The value of <strong>the</strong> variable cannot change<br />

2 2 7<br />

<strong>Cracking</strong> <strong>the</strong> <strong>Coding</strong> <strong>Interview</strong> | Knowledge Based<br />

pg 78<br />

When applied to a variable (reference): The reference variable cannot point to any o<strong>the</strong>r object<br />

on <strong>the</strong> heap<br />

When applied to a method: The method cannot be overridden<br />

When applied to a class: The class cannot be subclassed<br />

Finally<br />

There is an optional finally block after <strong>the</strong> try block or after <strong>the</strong> catch block Statements in <strong>the</strong><br />

finally block will always be executed (except if JVM exits from <strong>the</strong> try block) The finally block<br />

is used to write <strong>the</strong> clean up code<br />

Finalize<br />

This is <strong>the</strong> method that <strong>the</strong> JVM runs before running <strong>the</strong> garbage collector

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

Saved successfully!

Ooh no, something went wrong!