Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

access modifiers

 
Peter Warde
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

Peter
 
Fletcher Estes
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic