This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes access modifiers Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "access modifiers" Watch "access modifiers" New topic

access modifiers

Peter Warde
Ranch Hand

Joined: Aug 18, 2004
Posts: 71
class MyClass {

public static void main( String [] args ) {
// some code


My understanding here is that the class has default access ie cannot be seen outside it's package, and that the class visibility has priority over any method visibility that are wider. How then is it possibile to access the public main method with java MyClass 123 command line argument ( which it is ) when the class is default?

Fletcher Estes
Ranch Hand

Joined: Jul 01, 2004
Posts: 108
Access control applies between classes themselves, rather than between the JVM and classes. When you launch the JVM using the 'java' command, the same rules do not apply - all it needs to find a class and run its main method is the location on disk. This is a special relationship between the JVM and a class's main method, which is only recognised by the signature public static void main(String[] args)
It is sorta covered in the JavaRanch Style Guide.
subject: access modifiers
Similar Threads
Reduced visibility of inherited method
I Still Get the Same Compile Error
Please explain the concept of private constructor
Question - Philip Heller's book
Creating objects using Reflection