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 ; } } }...
{ public static void main(String args[]) { int i=1,n=10,s=0; System.out.print("Sum("+n+") = "); for (i=1;i;i++) { s += i;System.out.print(i+"+"); } System.out.println(i+" = "+(s+i)); } } 程序运行...
主要介绍了实例分析Java中public static void main(String args[])的意义,详细分析了Java主函数main关键字声明的具体含义和用法,需要的朋友可以参考下
public static void main( String args ); C. public static void main( String args[] ); D. public static void main( Graphics g ); E. public static boolean main( String a[] ); 2) 编译和运行以下代码的结果...
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、下列那个可以作为...
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) { String s = "abcdefg"; String t = ""; char[] charArray = s.toCharArray(); for (int i = charArray.length-1; i>=0; i--){ t=t+charArray[i]; } ...
一、选择题。 1. 编译Java Applet 源程序文件产生的字节码文件的扩展名...B、public static void main( String args[] ) C、public static int main(String [] arg ) D、public void main(String arg[] ) 答:B
源代码说明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 ; }
面向对象程序设计 开发期末模拟试卷PDF
public static void main(String[] args) { // 指令敘述rintln("我的第一支Java程式"); } } 我的第一支Java程式 ------- 若public class first_Java 改成 public class first 則Could not find the main ...
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[]){ x--; myMethod(); System.out.println(x + y + ++x); } public static void myMethod(){ y = x++ + ++x; } } A.compiletime error B....
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; ...
SCJP轻松过 SCJP学习指南 SCJP试题 scjp题库