• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Variable Argument Lists Question

 
Ranch Hand
Posts: 59
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 256
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)
 
Greenhorn
Posts: 7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Lorraine Batol
Ranch Hand
Posts: 59
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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!
 
reply
    Bookmark Topic Watch Topic
  • New Topic