您的位置:首页 > 其它

static 非法向前引用

2012-12-06 22:12 113 查看
public class ErrorDef2Test
{
	static int num2 = 20;
	//下面代码将提示: 非法向前引用
	static int num1 =  num2 + 2;
	//static int num2 = 20;
	public static void main(String[] args)
	{
		System.out.println("第1个数" + num1);
		System.out.println("第2个数" + num2);
	}
}

public class RightDef
{
	//下面代码将完全正常
	int num1 = num2 + 2;
	static int num2 = 20;
	public static void main(String[] args)
	{
		RightDef obj=new RightDef();
		System.out.println("第1个数" + obj.num1);
		System.out.println("第2个数" + num2);
	}
}
/*
第1个数22
第2个数20
请按任意键继续. . .
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐