如题:
class A
{
public static int i = 0;
++i;
}
class myclass
{
public static void main(String[] args)
{
A aa = new A();
A bb = new A();
// aa.i = 14;
System.out.printf("%d\n", A.i);
}
}
我以为会看到结果是2,但是提示的错误信息是
myclass.java:4: 错误: 非法的类型开始
++i;
^
myclass.java:4: 错误: 需要';'
++i;
^
2 个错误
我没有看懂,请帮我解答一下。
------解决方案--------------------
++i;是一条执行语句,怎么能直接放到类里面去呢,类里面只能声明变量。
------解决方案--------------------