Can we overload var-arg method with normal method?

class VarArgMethod3
{
  public static void m1(int...x)
{
System.out.println("var-arg method");
}
public static void m1(int x)
{  
System.out.println("general method");
}
public static void main(String[] args)
{
m1();
m1(10);
m1(10,20);
}
}
/*
Output:- var-arg method
general method
var-arg method

Explanation:- We can overload var-arg method with normal method but var-arg method will
get least priority means If no other method matched then only var-arg method
will get chance. This is exactly same as default case inside switch.

*/

0 comments: