Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Prototype of the main method

 
Sirish Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again Ranchers,
Came across this question in one of the mock tests online

The correct answer was supposed to be option A. My reasoning was that although the access level of main method has to be public , it would not cause a problem during compilation. It's only at runtime that we would get the error that "matching main () method is not found. So I thought that none of the options are valid
However the reason given by the mock exam was that the option A is as per the JLS. Any inputs on this one
Regards
Sirish
 
Dan Andrei
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the code compiles with the latest compiler from sun
when I run the program I get the message
"main method not public"
I looked in jls 2.0 pg 235 under chap. 12.3.3 and it seems it is an Illegal Access Error.
Now the java api says the following about it:
"Thrown if an application attempts to access or modify a field, or to call a method that it does not have access to.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed. "
So NORMALLY IT IS CAUGHT AT COMPILE TIME, so the answwer should be A
I did not found in the JLS any reference to the Main method signature, saying whta happens in diffrent situations.
Hope this helps...
 
Sirish Kumar
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dan,
Thanks for that neat explanation..I agree that the code compiles fine with the new compiler. Hence the options were misleading. May be the mock exam was out dated and the question was drafted with an old compiler that was giving the error.
Thanks again
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic