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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

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

SOLUTIONS<br />

pg 78<br />

Final<br />

When applied to a variable (primitive): The value of <strong>the</strong> variable cannot change.<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.<br />

2 2 7<br />

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

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

Saved successfully!

Ooh no, something went wrong!