In this chapter we will discuss the main function.
For this function everyone is not unfamiliar, and all are accustomed to. But there are some things that are worth summarizing.
1. Normal Main
Package Com.ray.test;public class Maintest {public static void main (string[] args) {}}
Nothing special. is an empty method of main
2. The main without static
Package Com.ray.test;public class Maintest {public void main (string[] args) {}}
Compile as passed, just can't run. A run will report Nosuchmethod anomalies.
3. Main with no references
Package Com.ray.test;public class Maintest {public static void main () {}}
Compiled as passed. Just can't run. A run will report Nosuchmethod anomalies.
4. The main of the string is the number of references
Package Com.ray.test;public class Maintest {public static void main (String args) {}}
Compiled as passed. Just can't run, a run will report Nosuchmethod exception
5. Have final main
Package Com.ray.test;public class Maintest {public static final void main (String args) {}}
Compile as passed, just can't run. A run will report Nosuchmethod anomalies.
6. Main with return value
Package Com.ray.test;public class Maintest {public static int main (String args) {return 0;}}
Compile the same pass, just can't run, a run to report Nosuchmethod exception
7. Explanation
Now here's an explanation of the above main, and in fact all of the above main, we've all been misled.
All of the main functions above are not what we call a main function that can be executed. It's just a normal function called Main.
We can build a common main function that we know in the following
Or the technical point is that we overload (note: Not rewrite) main this function, but our JVM only recognize his format of the main function, otherwise. class file cannot be executed
Summary: This chapter mainly introduces you do not know the main function, in fact, here is the title party, hehe.
This chapter is here, thank you.
-----------------------------------
Folder
Know the java-feature from scratch-you don't know the main function