• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main() method????

 
Nasir Khan
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 175
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3776
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
madhumathi k
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

main method need not have this exact signature : public static void main
Refer http://developer.java.sun.com/developer/bugParade/bugs/4252539.html
http://www.ibiblio.org/javafaq/reports/privatemain.html

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 !
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic