338
技術社區[雲棲]
Java麵向對象基礎--理解main方法
public class StaticDemo08{ public static void main(String args[]){ fun(); } public static void fun(){ //可以由主方法直接調用 System.out.println("hello world!"); } };
public void fun(){ //不能由主方法直接調用 System.out.println("hello world!"); }
如不加static定義方法,則main方法不能調用。
public class StaticDemo08{ public static void main(String args[]){ if(args.length!=3){ // 輸入的參數如果不足3個,則出錯 System.out.println("輸入的參數不足三個,程序退出~") ; System.exit(1) ; // 直接退出此程序 } for(int i=0;i<args.length;i++){ // 循環輸出輸入的參數 System.out.println("第"+(i+1)+"個參數:" + args[i]) ; } } };
java StaticDemo08 "hello world" two three
最後更新:2017-04-03 16:49:06