0
How can I fill this array with numbers (1 to 10)
private Account[] accounts = new Account[10]
3 ответов
+ 1
If you want new accounts array
Replace
accounts[i] = i+1;
With
accounts[i] = new Account();
+ 1
A method in same class because the Account is private, using a for loop
public fillArray() { // can also be private if you only call it from constructor
for(int i=0;i<10;i++){
accounts[i] = i+1;
}
}
0
thanks for answer, but didn't work :| this was about array of objects. and I have to create 10 objects from Account class.