How does java get to know which implementation object of interface to return?
<p>Please be gentle while answering, I am not a java developer (or developer in General)</p>

<p>While trying xml parsing with java I came across following - </p>

<pre><code>NodeList nodelist = document.getElementsByTagName("item");
</code></pre>

<p>Herein xml dom object let me collect all objects depending on tag name I provide, but return type is an Interface called - nodelist. Since interface can not be instantiated it was a bit surprising for me.</p>

<p>Keeping break point and debugging the code I realized that I actually get object for class DeepNodeListImpl which implements NodeList interface. </p>

<p>How does this happen? How does java know to return object of "some implementation" held by my Interface "object" in the statement declared above.</p>

<p>One more thing - while reading the java <a href="http://download.oracle.com/javase/1.4.2/docs/api/org/w3c/dom/NodeList.html" rel="nofollow">api</a> I found that IIOMetadataNode implements the NodeList but my previous code snippets does not get me object of type IIOMetadataNode </p>
