• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Siva kandasamy
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Got it.
thanks
siva
x38020
 
Anupam Sinha
Ranch Hand
Posts: 1090
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sivanantham
From JDK 1.4 onwards not using public for the main method is wrong.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic