title: Return type of iterator() method in java
body: <p>I am a new-comer in Java and in process of learning.
  I need a an answer of following question supported with valid theory.
  Consider the following line-</p>
  <pre><code>Iterator itr = al.iterator(); 
  </code></pre>
  <p>where <em>al</em> is some collection object of ArrayList (class) type.
  I want to know what is here the return type of</p>
  <h3>al.iterator()</h3>
  <p>It is not definitely of a primitive data type, then it could be an <strong>object</strong> , but since every object belong to a class then it is of <strong>which class</strong>. Documentation and books etc says it has return type of Iterator. But <em>Iterator</em> is an interface. On other hand we say an interface could not have a direct object. Although interface variable could refer to an object of a class or classes that implements it.</p>
  <h3>-</h3>
  <p>So the above syntax is correct (as Iterator variable <em>itr</em> could be used to refer to an object of some class implementing it). But in realty it is object of which class?  And can substituting <em>itr</em> with reference variable of that class will cause no error (I have tried substituting <em>itr</em> with ref. variable of ArrayList class in above line but that causes an error). I am using this syntax very often also in Generics form, but dont know the theory behind this. And I am supposing I am lacking a very basic concept here. Please rectify.</p>