Problems of learning classes

I don’t understand why the order of the messages printed like this

Hi there!

The main() method is the entry point for a program, meaning that the Java Virtual Machine (JVM) will invoke it directly when the program is executed (when you press the “Run” button, in the context of Codecademy’s learning environment).

The code inside the main method will command the execution of the program, so the first line printed to the console is “Start of the main method” because it is the first line of the main method. Next the program encounters the line Store lemonadeStand = new Store(), so the Store’s constructor is called and the second line (“I am inside the constructor method”) is printed. Now we reach the third line System.out.println(lemonadeStand), which prints the reference ([email protected]) to the object that was created in the previous line.

2 Likes