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.1 In terms of inheritance, what is <strong>the</strong> effect of keeping a constructor private?<br />

SOLUTION<br />

pg 78<br />

Declaring <strong>the</strong> constructor private will ensure that no one outside of <strong>the</strong> class can directly instantiate<br />

<strong>the</strong> class. In this case, <strong>the</strong> only way to create an instance of <strong>the</strong> class is by providing<br />

a static public method, as is done when using <strong>the</strong> Factory Method Pattern.<br />

Additionally, because <strong>the</strong> constructor is private, <strong>the</strong> class also cannot be inherited.<br />

2 2 5<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!