• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can methods with multiple arguments(Varargs) overload or override

 
subodh k kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Virendrasinh Gohil
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1051
Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you can do it
 
subodh k kumar
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thankyou everyone for your valuable contribution.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic