声明Java对象数组

时间:2013-11-07 00:56:21

标签: java

我有以下代码,我已多次修改:

public class double3 {
    public double x=0;
    public double y=0;
    public double z=0;
    public double3(double a, double b, double c){
        this.x=a;
        this.y=b;
        this.z=c;
    }
}


double3[] samples = new double3[4];//syntax error on token ";", { expected after this token
samples[0]=new double3(1,2,3);

这里发生了什么,eclipse试图对我说什么?

1 个答案:

答案 0 :(得分:2)

陈述

double3[] samples = new double3[4];
samples[0] = new double3(1,2,3);

应该在代码块中,例如方法,构造函数或实例初始值设定项