*
The moose likes Beginning Java and the fly likes can methods with multiple arguments(Varargs) overload or override Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "can methods with multiple arguments(Varargs) overload or override" Watch "can methods with multiple arguments(Varargs) overload or override" New topic
Author

can methods with multiple arguments(Varargs) overload or override

subodh k kumar
Greenhorn

Joined: Aug 19, 2009
Posts: 16
In Java 5 , The varargs functionality allows multiple arguments to be passed as parameters to methods. It requires the simple ... notation for the method that accepts the argument list and is used to implement the flexible number of arguments. eg.
void argtest(Object ... args) { for (int i=0;i <args.length; i++) { } }

Question is Can we override/overload this method?

SCJP1.4 , SCWCD 5
Virendrasinh Gohil
Ranch Hand

Joined: Jun 09, 2004
Posts: 46
subodh k kumar wrote:In Java 5 , The varargs functionality allows multiple arguments to be passed as parameters to methods. It requires the simple ... notation for the method that accepts the argument list and is used to implement the flexible number of arguments. eg.
void argtest(Object ... args) { for (int i=0;i <args.length; i++) { } }

Question is Can we override/overload this method?


Theoratically asnwering, YES. Following all are valid cases. You can override it in subclass as well.


The point is, the choice has to be made depending upon the business requirement. Do you really need this sort of overloading? If so, why?

Compiler will not stop you surely.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40064
    
  28
Virendrasinh Gohil wrote: . . . Do you really need this sort of overloading? . . .

Compiler will not stop you surely.
Your manager at work will, however. And will stop your pay cheques, too
Shanky Sohar
Ranch Hand

Joined: Mar 17, 2010
Posts: 1051

yes you can do it


SCJP6.0,My blog Ranchers from Delhi
subodh k kumar
Greenhorn

Joined: Aug 19, 2009
Posts: 16
Thankyou everyone for your valuable contribution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can methods with multiple arguments(Varargs) overload or override