Hi, I,m new to javaRanch and preparing for the exam. I,ve a problem . Correctly defined main() method is said to be public static void main(String[] u){} I tried with private static void main(String[] u){} final static void main(String[] u){} protected static void main(String[] u){} static void main(String[] u){} All of them compiled and run without any change. Could anyone help me on this?? Nasir Khan.
Sasikanth Malladi
Ranch Hand
Joined: Nov 04, 2000
Posts: 175
posted
0
All the compiler checks to see is whether or not a main method is present. That's good enough. It will compile but when you try to run it, the JVM will check to see if there exists a main method looking like: public static void main(String somevar[]) and if it's not found, you get an error.
Paul Anilprem
Enthuware Software Support
Ranch Hand
Joined: Sep 23, 2000
Posts: 2547
posted
0
Actually, it compiles as well as runs with other modifiers diff. JDKs. But according to the specs and for the purpose of the exam, it should be public. -Paul. ------------------ Get Certified, Guaranteed! (Now Revised for the new Pattern) www.enthuware.com/jqplus
but for the sake of the certification exam just forget what is mentioned in the above sites and remember the signature of the main method given above. HTH !