File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt in Devaka's Final Exam 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 "Doubt in Devaka Watch "Doubt in Devaka New topic

Doubt in Devaka's Final Exam Question.

Abhi vijay
Ranch Hand

Joined: Sep 16, 2008
Posts: 509

I have doubts in Line 1 as marked above.
In line 1 even if I change the statement to static void capture(Long[] x){
Then I get compiler Error. Why does that happen? Considering Long[] x and Long ... x are considered to have the same method signatures??
Abhishek Bhat

Joined: Jan 01, 2009
Posts: 25

Hi Abhi,

The answer to your question lies in the names of the two concepts. One is an array, meaning, a GROUP and the other is VAR-ARGS which means Variable arguments, implying, the length of the ARGUMENTS can VARY. so if you have a NO-ARG method or a method with a certain number of arguments, the VAR-ARGS would accept it happily . THIS purpose however, cannot be fulfilled by an ARRAY . I beleive because of this inefficiency of the Array, the var-args concept was introduced by the designers . I hope you understood ..

Let me re-iterate, the difference lies in the names itself...

Gud luck !
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Quite simply an Array and a Varargs are two different specific things. An array holds a collection of objects (or references to) and Varargs (variable [amount of] arguments) is a parameter of what you can enter to the argument. Varargs reduce the need to overload in that it provides the ability to enter any number of arguments. As you can see they are indeed different items!

Hope this helps to!

be a well encapsulated person, don't expose your privates, unless you public void getWife()!
I agree. Here's the link:
subject: Doubt in Devaka's Final Exam Question.
It's not a secret anymore!