In core Java program, execution starts from main method when you type java main-class-name, JVM search for public static void main(String args[]) method in that class and if it doesn't find that method it throws error NoSuchMethodError:main and terminates.
First, why public? 可从任何地方访问此类成员
Propose it is private, then this method can not access outside the class, how jvm excute it?
Because main() method can excute in any java runtime evnironment, JVM need to access and execute it.
Any method or variable which is declared public in Java can be accessible from outside of that class, so declare public.
Second, why static? main()方法不应依赖于要创建的任何类的实例
Propose removed static, in order to excute main(), JVM has to create instance of main Class.
but constructor can be overloaded and can have arguments, ther would be no consistent way for JVM to create instance and find main method
Thrid, why void? 不返回任何值
Main() can be overloaded, from the entry point of class, it is not supposed to return any value.
相关推荐
public static void main String args[] throws InterruptedException { MainFrame mainFrame; try { mainFrame new MainFrame ; mainFrame loadGame ; } catch Exception e { e printStackTrace ; } }...
public static void main String args[] throws InterruptedException { MainFrame mainFrame; try { mainFram e new MainFrame ; mainFrame loadGame ; } catch Exception e { e printStackTrace ; } } }...
2. `public static void main(String args[])` 是Java程序的入口点,程序从这里开始执行。 3. `int i=1, n=10, s=0;` 分别声明并初始化了三个整型变量,`i`作为循环计数器,`n`为要累加到的数,`s`用于存储累加的...
C、public static void main(String args) D、public static void main(String args[]) 2、下列哪个是JDK提供的编译器( )。 A、java.exe B、javac.exe C、javap.exe D、javaw.exe 3、下列那个可以作为...
public static void main(String[] args) throws Exception{ System.out.print("The input Fahrenheit is "); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int f = Integer....
public static void main(String[] args) { try { return; } finally { System.out.println("Finally"); } } } ``` - **问题:** 运行结果是什么? - **答案解析:** - `finally`块在方法返回之前总是被执行...
public static void main(String[] args) { for (int i = 1; i ; i++) { System.out.println(fibonacci(i)); } } public static int fibonacci(int n) { if (n == 1 || n == 2) { return 1; } else { ...
Java中的`public static void main(String[] args)`是每个可独立执行的Java程序的入口点,它的每一个部分都有特定的含义: 1. `public`:这是一个访问修饰符,表示该方法可以被任何其他类访问,无论它们是否在同一...
public static void main(String[] args) { String s = "abcdefg"; String t = ""; char[] charArray = s.toCharArray(); for (int i = charArray.length-1; i>=0; i--){ t=t+charArray[i]; } ...
源代码说明Java程序设计... public static void main(String[] args) { int a=155; float b=21.0f; System.out.println("a="+a+",b="+b); //输出a,b的值 System.out.println("a/b="+(a/b)); //输出a/b的值 } }
引入这个jar包 下面的代码可以调用 public static void main String args[] { Draw draw new Draw ; draw a args ; }
public static void main(String args[]){ /*---- ------*/ } System.out.println("Programming in Java is fun!"); 程序填空。 在屏幕上显示如下网格。 +---+---+ +---+---+ import java.io.*; public class Test...
MYJ2C将编译的Java方法转换为C语言。... public static void main(String args[]) { System.out.println("Hello, world!"); } } After public class App { public static native void main(String args[]); }
public static void main(String args[]) { A aa1=new A(); A aa2=new A(); A aa3=new A(); aa1.i=20; aa2.show(); System.out.printf("%d\n",aa3.i); } } //不再是某个对象的,是所有对象共有的。静态...
public static void main String [] args { String str ""; for int i 1; i < 1000; i++ { for a 2; a < int i 2; a++ { if i % a 0 { break; } } if a > int i 2 { str+ String ...
public class abc { public static void main(String args [ ]) { AB s = new AB("Hello!","I love JAVA."); } } class AB { String s1; String s2; public AB(String str1, String str2) { s1 = str1; s2 = str2; ...
在Java应用程序中,main()方法可以接收命令行参数,例如,TestMain类中main()方法的定义为:public static void main(String args[]){ System.out.println("打印main方法中的输入参数!"); for(int i=0;i<args....
public static void main String[] args { System out print "Enter the radius and length of a cylinder:" ; Scanner input new Scanner System in ; float radius input nextFloat ; float ...
public static void main(String args[]) { BigInteger n1=new BigInteger("987654321987654321987654321"), n2=new BigInteger("123456789123456789123456789"), result=null; result=n1.add(n2);//n1和n2...
1 JAVA基本概念public static void main(String args[]){public static void main(String