代码如下:[code="java"]public class Parent {
private static int i = 0;
static int j = 0;
protected static int k = 0;
public static int m = 0;
System.out.print(k);
public static void main(String[] args) {
System.out.print(i);
System.out.print(j);
System.out.print(k);
System.out.print(m);
}
}
[/code]
运行到System.out.print(k);时会爆出VariableDeclaratorId expected after this token,但当放在语句块或函数中时却不会出错,这是为什么啊?
java中只有属性和方法,System.out.print(k); 不属于属性 就应该在方法里。over
第六行编译不会过,
不知道你是不是意思要在类装载的时候打印k,如果是这样代码这样写
[code="java"]
static{
System.out.print(k);
}
[/code]