【发布时间】:2015-03-09 04:10:36
【问题描述】:
如果有数组如:
//....
int[] anArray;
anArray = new int[3];
anArray[0] = new otherClassWConst( x, y , z);
anArray[1] = new otherClassWConst( x, y , z);
anArray[2] = new otherClassWConst( x, y , z);
//....
x、y 和 z 的值都与数组中其他对象的其他 x、y 和 z 的值不同。 (这有意义吗?就像 anArray[0] 中 x 的值与 anArray[2] 中的值不同)。 注意:另一个类的构造函数需要这些参数,我不确定这是否重要
我如何在不同的类中获取每个数组值中的一个参数的值(例如,y 的值)。例如,有没有一种方法可以获得 Ys 的所有三个值,以便我可以将它们全部加到另一个类中?
例如
//code attaining only the y values of the array
overallValueOfY = Y + Y + Y; // or something of that nature
//life continues over here.
如果有什么不清楚的地方请告诉我,我已经尽力解释了。感谢您的考虑。
【问题讨论】:
-
显示你的班级结构。
标签: java arrays class parameters constructor