Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes The method main must be declared public, static, and void. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "The method main must be declared public, static, and void." Watch "The method main must be declared public, static, and void." New topic
Author

The method main must be declared public, static, and void.

Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Hi there,
As per the JLS,
The method main must be declared public, static, and void.
See the code below at "<===", it do not have the key word public,
but it works. I am little confused.
thanks
siva
x38020

Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

Most cultures have laws against stealing. In theory, if you steal a loaf of bread, you get sent to jail. But in practice, you may or may not get caught, yes?
Same here. The rule says it must be public. Some JVMs might catch you if you violate this rule. Others, however, won't. Sun's won't.


[Jess in Action][AskingGoodQuestions]
Siva kandasamy
Ranch Hand

Joined: Dec 31, 2002
Posts: 139
Thanks. Got it.
thanks
siva
x38020
Anupam Sinha
Ranch Hand

Joined: Apr 13, 2003
Posts: 1088
Hi Sivanantham
From JDK 1.4 onwards not using public for the main method is wrong.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The method main must be declared public, static, and void.