• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

passing mutiple args to a method/constructor

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Is it ok to pass mutiple arguments to a method when they are not in the correct order?

[CODE]class a {
public a(int x, float y)
{//do stuff here}
}
class usinga{
a A = new a(3.2F, 7);
}
[CODE]
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Megs Maquito:

Is it ok to pass mutiple arguments to a method when they are not in the correct order?



No. They have to be in the order that the method is expecting them.
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As Joanne said no you can't do that. But even more importantly, you could have easily found this out yourself with a simple little test program. It's a good habit to get into to test things yourself. There's no substitute for practice and experience.
 
Ranch Hand
Posts: 2108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you have to send args in same order as the method was defined

same variable types too, but okay to use polymorphism

e.g. if method wants args Animal, Array of Cars

then you can pass: Dog, Array of Corollas

as dog is an animal, and corolla is a car, if you define their hierarchy as such
 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks so much all!
 
reply
    Bookmark Topic Watch Topic
  • New Topic