Why does each element in this array of objects get overwritten by the last object?

前端 未结 4 920
无人及你
无人及你 2020-12-11 11:35

I have the following code:

public static void main(String[] args) {
  Player players[] = new Player[2];
  Scanner kb = new Scanner(System.in);
  System.out.p         


        
4条回答
  •  执笔经年
    2020-12-11 12:04

    With the keyword static you have made name a class variable which is NOT an instance variable. A class variable is common to all the objects. Click for some more reading.

提交回复
热议问题