private int anzahlWagen = 0; static Wagen[] wagenList; public static void main(String[] args){ wagenList = new Wagen[6]; for(int i = 0;i < wagenList.length;i++){ wagenList[i] = null; } addWagen(5,9); for(int i = 0;i < wagenList.length;i++){ System.out.println(wagenList[i].getFirstClass()); } } public static void addWagen(int pFirst, int pSecond){ boolean wagenAdded = false; for(int i = 0;i < wagenList.length;i++){ if(wagenList[i] == null){ if(wagenAdded == false){ wagenAdded = true; wagenList[i] = new Wagen(pFirst, pSecond); } } } wagenAdded = false; }
It adds the value 5 to all objects within the array. The class "Wagen" consists of two private int variables, and get-methods.