Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing mutiple args to a method/constructor

 
Megs Maquito
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • 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]
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • 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.
 
Hentay Duke
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • 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.
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks so much all!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic