0

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.   
2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by hszforu
1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.