• Post Reply Bookmark Topic Watch Topic
  • New Topic

why overloading doesn't work for this ?  RSS feed

 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class A {
public static void main(String args[]) // 1st method
{
// the required things to be done
}

public static void main(String args[],String args1[]) //2nd method
{
// the required things to be done
}
}

The thing over here is wen i givejava A 2 3 it must take the Second method but the thing is it takes the first method ..... how should i do it ......???
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The second method can never be an entry point into a Java application. Period. But then again why would you need it to? All the arguments you pass at the start of the application are available through the args String[]. If you want to call the second method from your main entry point, you just have to wrap the arguments in String arrays and call it. But I'm not sure why that would be useful.
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But to get the two parameters, in your first method, try:And of course, you must first check that the input arguments exist and if you are expecting numbers then do the appropriate conversion.
 
Arun C. Giridharan
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On checking parameters Tom...i can apply conditional statement and go to the other method. That's okay but as per


Garrett Rowe:

If you want to call the second method from your main entry point, you just have to wrap the arguments in String arrays and call it.



How can i do this in cmd prompt ???
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun Giridharan wrote:How can i do this in cmd prompt ???


You can't. You do it in the main(String[] args) method. As has been said, there is only one starting point for a Java application, pre-defined by the language specification, without hope of modification. So the app will always start in public static void main(String[]), and from there, if you wanted to, you can call public static void main(String[], String[]).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!