为什么我的数组中的所有值都会立即更改? [英] Why are all my values in my array changing at once?

查看:64
本文介绍了为什么我的数组中的所有值都会立即更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Salesman[] salesTeam = new Salesman[number];
        
        salesTeam[0] = new Salesman();
        salesTeam[1] = new Salesman();
        
        salesTeam[0].setName("A");
        salesTeam[1].setName("B");
        salesTeam[0].setSales(50);
        salesTeam[1].setSales(100);





结束时将两个值都设为B和100



为什么会这样?



如果需要,我可以提供更多信息,但我觉得问题在于此代码。



Ends having having both values as "B" and "100"

Why is this?

I can provide more info if needed, but I feel like the issue is within this code.

推荐答案

该类中的字段设置为静态。
The fields in the class were set to static.


这篇关于为什么我的数组中的所有值都会立即更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆