• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main method

 
shandilya popuru
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi everyone

though main method is said to be declared public it works fine without it
what is the reason n why it shoud be decld public
 
Ed Lance
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure what you mean about "works fine". My guess is it COMPILES fine but with out the correct signature it is not the entry point to your program. Double check to make sure you aren't really running your previously compiled file.

Another example is that I can have the following main method:
public static void Main(String[] args){
}
...but again it's not the entry point for my application.
 
Natesh Kurup
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The entry point into the program has to be


The code would compile perfectly if it has not been declared public but wont run. Check whether an existing program with same name exists in the classpath

Regards

Natesh
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is some inconsistency between the Java versions in the way they treat the non-public main methods.
If I remember correctly, non-public main methods will work fine in 1.3 & 1.2.2, but not in other versions.
With version 1.4.1, it gives Runtime error "Main method not public"
Which version are you using?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic