阅读338 返回首页    go 阿里云 go 技术社区[云栖]


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

  上一篇:go Makefile模板 之CC指定编译器
  下一篇:go 100个最受欢迎的机器学习课程视频