| Author |
private main method in java
|
gokulanand narayanan
Greenhorn
Joined: Feb 16, 2006
Posts: 23
|
|
Hi, Can i have a class like this? and will i be able to run this? class A { private static void main(String args[]) { System.out.println("Hello World!"); } } I am able to do this (only with the version jdk1.3.1_20) Can anyone explain me!!! Thanks Gokul
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
You can certainly have such a class. You should not be able to run it, using the normal "java[.exe]" launcher; to do that, your class and its main() should be public. If you find you can run it, that might be a feature of your ancient Java version.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Peter Chase: If you find you can run it, that might be a feature of your ancient Java version.
Or rather a bug...
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
Raghavan Muthu
Ranch Hand
Joined: Apr 20, 2006
Posts: 3327
|
|
Originally posted by Peter Chase: .. If you find you can run it, that might be a feature of your ancient Java version.
I wonder was there an earlier version of Java supporting this first of all?
|
Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
|
Yes, older versions of Java allowed this, for no apparent reason. This changed around JDK 1.4. The JLS has always said that the main method must be public, although it doesn't say what should happen if it's not publuc. So one might argue that this behavior was simply unspecified, not technically a bug. Regardless, anyone who uses a private main method should consider the code to be extremely unreliable at best.
|
"I'm not back." - Bill Harding, Twister
|
 |
 |
|
|
subject: private main method in java
|
|
|