title: Method overloading using varargs in Java
body: <p>The following code in Java uses <strong>varargs</strong> to overload methods.</p>
  
  <pre><code>final public class Main
  {
      private void show(int []a)
      {
          for(int i=0;i&lt;a.length;i++)
          {
              System.out.print(a[i]+"\t");
          }
      }
  
      private void show(Object...a)
      {
          for(int i=0;i&lt;a.length;i++)
          {
              System.out.print(a[i]+"\t");
          }
  
          System.out.println("\nvarargs called");
      }
  
      public static void main(String... args)
      {
          int[]temp=new int[]{1,2,3,4};            
  
          Main main=new Main();
          main.show(temp);
          main.show();         //&lt;-- How is this possible?
      }
  }
  </code></pre>
  
  <hr>
  
  <p>The output of the above code is as follows.</p>
  
  <pre><code>1        2        3        4
  
  varargs called
  </code></pre>
  
  <hr>
  
  <p>The last line <code>main.show();</code> within the <code>main()</code> method invokes the <code>show(Object...a){}</code> method which has a <strong>varargs</strong> formal parameter. How can this statement <code>main.show();</code> invoke that method which has no actual arguments?</p>