• 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

Var args question

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1.Class Voop {
2. Public Static void main(String [] args) {
3. doStuff(1);
4. doStuff(1,2);
5. }
6. // Insert code here
7.}

Which, inserted independently at line 6, will compile? (Choose all that apply?)

A. static void doStuff(int... doArgs) { }
B. static void doStuff(int [] doArgs) { }
C. static void doStuff(int doArgs...) { }
D. static void doStuff(int...doArgs, int y) { }
E. static void doStuff(int x, int...doArgs) { }


Ans: A and E.

How come E is correct. If line E is inserted, it expects two Args, but the first dostuff() doesn't have two args?
Does the var-arg which is the second argument mean zero or many?

Appreciate your help in understaning this. Thank you.

Regards,
Anand.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anand Reng wrote:
Does the var-arg which is the second argument mean zero or many?


Yes. and Varargs can be used only in the final argument position
 
Greenhorn
Posts: 4
Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
varargs accepts values 0 to n.
 
Anand Reng
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Guys.
 
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic