【发布时间】:2018-01-05 21:13:58
【问题描述】:
为什么会出现这个错误?请看以下代码。
class Test{
Hello h=new Hello();
}
class Hello{
int a=10;
System.out.println(a); // error identifier expected
}
【问题讨论】:
-
你希望它在没有 main 方法的情况下如何运行?
-
这有很多问题。没有 main() 函数。没有任何块的 System.out 函数。在 Test 中创建一个 main() 函数,并在将 System out 语句设为静态后将其放入静态中。
标签: java class variables scope