Forums Register Login

Calling main() method

+Pie Number of slices to send: Send
Hi,
I wrote a program like the one below.
public class Test {
private static void main(String args[]) {
System.out.println("Hello");
}
}
Instead of declaring main method as public, I declared it as private.
But still the program was running without any error and printed "Hello".
Can anyone please tell what is actually happening?
Thankx in advance...
+Pie Number of slices to send: Send
Obviously it depends of java (JVM).
How it works - search in public class the main function, and
check its signature (type of argument, output value, static/not
static, public/private/protection/default)
Probably used version of JVM don't have check of access attribute,
or the check accepted not only public, but your case.
What is the problem?
Exists a lot of JVM.
And men writing JVM aren't alwais perfect.
+Pie Number of slices to send: Send
Yes .. It does work perfectly OK...
As a matter of fact private main method issue is a known problem with a bug report opened against it.
Sun has however closed the bug report and the problem will NOT be fixed.
But be careful while taking the certification exam.
+Pie Number of slices to send: Send
OK, so Sun doesn't think that is important.
Igor
Sun Uncertified java programmer.
[ December 22, 2003: Message edited by: Igor Ko ]
+Pie Number of slices to send: Send
Note that this was an issue of older JVMs. Sun's latest 1.4.2 JVM requires that the main method be public.
permaculture is largely about replacing oil with people. And one tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 574 times.
Similar Threads
main method in base class
Doubt about "public" in main
Main Method
problems running code
WHy does main() work with private accessibility?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 04:37:50.