• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Prototype of the main method

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic