初始化对象数组并传递值
我知道论坛里有很多这样的问题,但搜索了好一阵子还没有找到答案。我对编程也很陌生,所以请不要攻击我。
我想在我的类中创建 8 个对象并向它们传递不同的值。
fe
public class exampleClass(){
int value;
}
然后初始化它们:
for(int i=0; i<7; i++){
exampleClass c= new // I get lost at this point
//and how can we pass "i" to the var "value" inside the new objects?
}
非常感谢!
I know there are plenty of question like this in the forum, but after searching for a good while I havent found the answer. I'm also very new to programming so dont flame me please.
I want to creat 8 objects off my class and pass different values to them.
f.e.
public class exampleClass(){
int value;
}
and then init them:
for(int i=0; i<7; i++){
exampleClass c= new // I get lost at this point
//and how can we pass "i" to the var "value" inside the new objects?
}
thanks a lot!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要为
ExampleClass
提供一个构造函数来填充该值。例如:You need to give
ExampleClass
a constructor to populate the value. For example: