File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how many arguments should at least passed to a var-args in a method? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "how many arguments should at least passed to a var-args in a method?" Watch "how many arguments should at least passed to a var-args in a method?" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how many arguments should at least passed to a var-args in a method?
 
Similar Threads
Calling Supermost class's method with sub most's class reference
static
debuging a static block
Anonymous inner class
Anonymous class