| Author |
how many arguments should at least passed to a var-args in a method?
|
prakash Venugopal
Greenhorn
Joined: Dec 28, 2011
Posts: 8
|
|
class VarargExa
{
public static void main(String...args)
{
go();
}
static void go(short...args)
{
System.out.println("Inside of go");
}
}
The out put is: Inside of go
|
 |
saloni jhanwar
Ranch Hand
Joined: Feb 09, 2012
Posts: 583
|
|
|
0 to many.
|
Tell the difficulties that i am difficult.
|
 |
gurpeet singh
Ranch Hand
Joined: Apr 04, 2012
Posts: 867
|
|
prakash Venugopal wrote:class VarargExa
{
public static void main(String...args)
{
go();
}
static void go(short...args)
{
System.out.println("Inside of go");
}
}
The out put is: Inside of go
Would like to add to what saloni said. when you pass arguments to method which accepts var-args they are passed in the form of an array of the type of the var-arg declared. in above case if you invoke go like for e.g
go(2,3,4) the arguments will be passed as short array. you can say that the var-args argument is nothing but array of shorts , because of which you can write main method signature as :
main(String[] args) or main(String... args)
which means if you try to overload the methods as go(short...args) and go(short[] s) it will give you error that the method name already exists.
|
OCPJP 6(100 %) OCEWCD 6(91 %)
|
 |
saloni jhanwar
Ranch Hand
Joined: Feb 09, 2012
Posts: 583
|
|
gurpeet singh wrote:
prakash Venugopal wrote:class VarargExa
{
public static void main(String...args)
{
go();
}
static void go(short...args)
{
System.out.println("Inside of go");
}
}
The out put is: Inside of go
Would like to add to what saloni said. when you pass arguments to method which accepts var-args they are passed in the form of an array of the type of the var-arg declared. in above case if you invoke go like for e.g
go(2,3,4) the arguments will be passed as short array. you can say that the var-args argument is nothing but array of shorts , because of which you can write main method signature as :
main(String[] args) or main(String... args)
which means if you try to overload the methods as go(short...args) and go(short[] s) it will give you error that the method name already exists.
Nice.
|
 |
 |
|
|
subject: how many arguments should at least passed to a var-args in a method?
|
|
|