You explicitly told java what class to load on the command line or in a .jar's Manifest if you're running an executable jar.
The Java Specification Chapter 12 goes briefly into what happens when the JVM starts up. (The JVM Specification Chapter 5 covers it in more detail.)
In short:
java try1
will load the try1
class, then link, verify, resolve, and initialize it.
Once that's done, it will look for a main method that is public
, static
, and void
that accepts an array of String
s, then it will execute that method.
The JVM doesn't care that your class wasn't public. As the first class loaded, it is the current compilation unit and initial access control is calculated from it.