Two Laptop Bag*
The moose likes Beginning Java and the fly likes main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "main method" Watch "main method" New topic
Author

main method

shandilya popuru
Ranch Hand

Joined: Dec 21, 2004
Posts: 95
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


sandy
Ed Lance
Ranch Hand

Joined: Aug 02, 2000
Posts: 38
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

Joined: Nov 23, 2004
Posts: 19
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

Joined: Mar 11, 2002
Posts: 1140
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?


Mani
Quaerendo Invenietis
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: main method