aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Var args 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 "Var args question" Watch "Var args question" New topic
Author

Var args question

Anand Reng
Greenhorn

Joined: Feb 11, 2013
Posts: 8

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.
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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
Dheeraj Singh Thakur
Greenhorn

Joined: Jun 18, 2012
Posts: 4

varargs accepts values 0 to n.
Anand Reng
Greenhorn

Joined: Feb 11, 2013
Posts: 8
Thanks Guys.
 
jQuery in Action, 2nd edition
 
subject: Var args question