Can we overload a method consisting 1-D array parameter with a method consisting var-arg parameter?
class VarArgMethod7
{
public static void m1(int[] i)
{
System.out.println("1 dimensional array parameter");
}
public static void m1(int...i)
{
System.out.println("var-arg method");
}
public static void main(String[] args)
{
m1(1,2);
}
}
/*
Output:- Compilation error
Explanation:- No, We cannot declare both (int[] i) and (int...i) in overloaded method.
*/
{
public static void m1(int[] i)
{
System.out.println("1 dimensional array parameter");
}
public static void m1(int...i)
{
System.out.println("var-arg method");
}
public static void main(String[] args)
{
m1(1,2);
}
}
/*
Output:- Compilation error
Explanation:- No, We cannot declare both (int[] i) and (int...i) in overloaded method.
*/
0 comments: