This is my code:

//VariableArguments1.java

public class VariableArguments1
{
  static void test(int ...v)
  {
    System.out.println("length:"+v.length);

    for(int x:v)
    {

        System.out.println("x="+x);
    }
  }
}

and

//VariableArguments1Test.java


public class VariableArguments1Test
{
    public static void main(String args[])
    {
        test(33,43,34,23,24);
        test(43,442);
        test();
    }
}







Following are the errors i am getting:


VariableArguments1Test.java:5: cannot find symbol
symbol  : method test(int,int,int,int,int)
location: class VariableArguments1Test
                test(33,43,34,23,24);
                ^
VariableArguments1Test.java:6: cannot find symbol
symbol  : method test(int,int)
location: class VariableArguments1Test
                test(43,442);
                ^
VariableArguments1Test.java:7: cannot find symbol
symbol  : method test()
location: class VariableArguments1Test
                test();
                ^


 I am not able to figure out what's wrong here.   

The problem is unrelated to the fact that test takes a variable number of arguments. The problem is that you're calling test as if it was a method of the VariableArguments1Test class, which it's not.

If you want to call a static method of another class, you'll need to specify the class when calling it (or use a static import). So you need to write VariableArguments1.test instead of just test.

Ok thanks, i understood.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.