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

DOUBT from scjp book

Abhishek Mantri
Greenhorn

Joined: Sep 06, 2007
Posts: 25
Given:
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) { }
Answer:
-> A and E use valid var-args syntax.
-> B and C are invalid var-arg syntax, and D is invalid because the var-arg must be the last of a method's arguments.(Objective 1.4)
MY QUESTION IS WHY "B" IS A WRONG OPTION???THIS QUERY IS FROM SCJP BOOK-CHAPTER 1
Gaurav Joshi
Greenhorn

Joined: Mar 08, 2008
Posts: 18
Hi Abhishek,

static void doStuff(int[] doArgs) { } expects the values passed as that of
int array(Remember its an Object).
Hence when you pass doStuff(1) and doStuff(1,2), it doesnt get called.
But,

will work fine
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Please see KeepItDown to find out why it is considered rude to type sentences with the caps-lock button down.

Tip:
You can always fix a post by clicking on the link in that post.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Abhishek Mantri
Greenhorn

Joined: Sep 06, 2007
Posts: 25
Thanks Gaurav
Sorry Ben..will remember it next time
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DOUBT from scjp book
 
Similar Threads
varargs doubt
var-args doubt clarification needed
about var-args
Gotcha: Varargs spoofs method signature [from Sierra/Bates book]
New type of var-args syntax (at least to me)