This question already has answers here:
Why can't I do assignment outside a method?
                                
                                    (7个答案)
                                
                        
                3年前关闭。
            
        

我在Eclipse中写数组有问题:

public class nizovi {
    int[] anArray;
    anArray = new int[10];

}


Eclipse说:


  “令牌“;”上的语法错误,“,”预期


如您所见,它看起来非常好。我不知道这是怎么回事。

最佳答案

如果要在类级别分配值,则必须一行执行:

public class nizovi {
    int[] anArray = new int[10];

}

07-24 09:45
查看更多