I\'m learning Java and I noticed that the main()
is put inside of a class. Why? I don\'t consider my main()
to be a member of any object. So please
You must put the main()
in a class. And, it must be static
(which means it is not a member of any Object
). When you launch the Java Runtime Environment (JRE) it will load that class and invoke the main()
.
This is covered by JLS-12.1 - Java Virtual Machine Startup which says in part,
The Java Virtual Machine starts execution by invoking the method
main
of some specified class, passing it a single argument, which is an array of strings. In the examples in this specification, this first class is typically calledTest
.