在数组中创建对象

时间:2017-09-15 05:51:29

标签: java arrays

创建一个数组SyskPin(大小n = 3)类行李,并创建一个具有完整构造函数的对象,为其提供价格字段,您将使用方法getInt() , getDouble()getString()读取这些字段。这个方法的代码建立在类ClassOfStaticMethods中。你可以修复我的代码,因为它可能是错的吗?

// with full constructor
ClassOfStaticMethods[] SyskPin = new ClassOfStaticMethods[3]; // i declare the array
for(int i =0; i <3; i++) { // the size is 3
ClassOfStaticMethods SyskPin = new ClassOfStaticMethods(2,2.1,"something",90,100); // the first 3 are int,double,String the other two i get from down
ClassOfStaticMethods clas=new ClassOfStaticMethods();
clas.setanother(90);
clas.getanother(90);
clas.setm(100);
clas.getm(100);

            SyskPin[nCount] =clas; //nCount is for fill the array

            nCount++;
        }

1 个答案:

答案 0 :(得分:0)

以下是您正在寻找的代码示例:

{{0, 44}, {375, 734}}