Meaningless Drivel is fun!*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 24183
    
  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.
 
 
subject: The method main must be declared public, static, and void.
 
Similar Threads
How to call the overridden method?
Overridiing
Exceptions - handle or declare rule
Local Class
mock exam question.can it be complied?