• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

main()

 
Wena Dollison
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've encountered a question from a sample exam and it says:
For a class to be executed in the command line, main() can have such modifiers: public, final and native.
I need some clarification about this. Why can a main() be native? What other modifiers can a main() method have?
Thanks in advance!
 
Dan Chisholm
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Wena Dollison:
I've encountered a question from a sample exam and it says:
For a class to be executed in the command line, main() can have such modifiers: public, final and native.
I need some clarification about this. Why can a main() be native? What other modifiers can a main() method have?
Thanks in advance!

Wena,
For the purposes of the exam, you should assume that
Section 12.1.4, Invoke Test.main, of the Java Language Specification is enforced by the JVM. In reality, many versions of the JVM do not enforce the JLS.
The compiler does not generate an error if you declare a main method that does not conform to the JLS. Instead, the JVM should enforce the rules at run time if you try to invoke the main method from the command line.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic