title: what is the advantage of declaring a reference variable as an interface type in JAVA?
body: <p>I was reading <a href="http://www.lsp4you.com/java/javaimages/06_Packages%20&amp;%20Interfaces.ppt" rel="nofollow noreferrer">this PowerPoint presentation</a> when I came across this:</p>
  
  <blockquote>
    <p>When you call a method through one of these references, the correct version will be called based on the actual instance of the interface being referred to. This is one of the key features of interfaces. The method to be executed is looked up dynamically at run time, allowing classes to be created later than the code which calls methods on them.</p>
  </blockquote>
  
  <p>Can anyone explain me about this concept? I referred few websites and book and I am still not clear about how this concept works. From above line it is known that it calls correct version of method. How does it work and when should I cast an object to interface type.</p>