aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Prototype of the main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Prototype of the main method" Watch "Prototype of the main method" New topic
Author

Prototype of the main method

Sirish Kumar
Greenhorn

Joined: Jan 28, 2004
Posts: 15
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

Joined: Jan 21, 2004
Posts: 92
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...


"Did anyone understand what I have just explained? ... because I did not!"
Sirish Kumar
Greenhorn

Joined: Jan 28, 2004
Posts: 15
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Prototype of the main method