【发布时间】:2014-01-09 04:47:13
【问题描述】:
我无法编译以下代码。无法理解这里的编译过程。为什么主类实例对其他类不可见(test1)。为什么它在编译时失败。请帮忙。
public class test {
public int i = 10;
public static void main(String[] args) {
System.out.println("test main");
}
}
class test1 {
test t = new test();
System.out.println(t.i);
}
【问题讨论】:
-
你的错误信息是什么?
-
你有多少个文件?它们各自的具体内容是什么?
-
这里是错误 test.java:9: error:
expected System.out.println(t.i); ^ test.java:9: 错误: 预期 System.out.println(t.i); ^ 2 个错误 -
@sp00m 只有 1 类。一个普通的 java 文件。
标签: java class compilation java-7 main