This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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()!
It is sorta covered in the JavaRanch Style Guide.
subject: Doubt in Devaka's Final Exam Question.
Similar Threads
Most specific Method-Overloading??
overloading example from examlab
Need help on Questions of wrapper classes
How to pass a long in ...Long ll = Long.valueOf(3L);//gives