Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main() method...

 
Shiaber Shaam
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a java programme has two main methods with same signature.... wat will happen..........
 
Ganesha Kumar
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You cannot have two methods with the same signature in a single Java file
 
Shiaber Shaam
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
then it will give compile time error.. is it?..... wat happens if i have String[] args as arg for one main() and String[] argv for another...
 
Chad Brown
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simple solution is to write a program with two main methods e.g.

public class TwoMains{

public static void main(String args[]){
}

public static void main(String[] args){
}

}

Compile it and you should get a compiler error stating that main has already been defined.
[ June 16, 2006: Message edited by: Chad Brown ]
 
Amod Mulay
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shiaber:
then it will give compile time error.. is it?..... wat happens if i have String[] args as arg for one main() and String[] argv for another...


hey change the argument to string,string and see what happens..it will compile....but compiler will always look for the main(String[] df)
sugniture first as it passes some default string can be empty to the main methpd for execution
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic