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 Variable Argument Lists Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Variable Argument Lists Question" Watch "Variable Argument Lists Question" New topic
Author

Variable Argument Lists Question

Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 43

Okay, I know I ask a lot. lol I just want to really understand this stuff inside-out so I could pass the OCJP, please bear with me. Thanks.

My study book is SCJP Sun Certified Programmer for Java 6 Study Guide Exam 310-065 by Kathy Sierra and Bert Bates. I'm a bit confused about something that is written about Variable Arguments Lists.
I will write the paragraph and mark the one that I have trouble in understanding:

- Var-arg type. When you declare a var-arg parameter, you must specify the type of the argument(s) this parameter of your method can receive. (This can be a primitive type or an object type.) //Got it
- Basic syntax. To declare a method using a var-arg parameter, you follow the type with an ellipsis (...), a space, and then the name of the array that will hold the parameters received. //Got it
- Other parameters. It's legal to have other parameters in a method that uses a var-arg. //Um, can anyone rephrase this for me? I don't get it. . I thought it can only have one var-arg in a method.
- Var-arg limits. The var-arg must be the last parameter in the the method's signature, and you can have only one var-arg in a method. //Got it


Thanks.
Praveen Kumar M K
Ranch Hand

Joined: Jul 03, 2011
Posts: 256
It means that there can be other parameters in the method signature along with var-args parameter.

E.g.: void varArgsMethod(float param1, String param2, Integer...varargParam)
Mrinal Singhania
Greenhorn

Joined: Sep 30, 2012
Posts: 7
Praveen Kumar M K wrote:It means that there can be other parameters in the method signature along with var-args parameter.

E.g.: void varArgsMethod(float param1, String param2, Integer...varargParam)


However, the var-args parameter should be last in the parameter list.
Yin Stadfield
Ranch Hand

Joined: Oct 13, 2012
Posts: 43

Mrinal Singhania wrote:
Praveen Kumar M K wrote:It means that there can be other parameters in the method signature along with var-args parameter.

E.g.: void varArgsMethod(float param1, String param2, Integer...varargParam)


However, the var-args parameter should be last in the parameter list.


Just got confused, thanks for clearing things up Praveen and Mrinal!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Variable Argument Lists Question