我正在尝试创建一个包含 10 个帐户对象的数组,但是当我尝试运行它时,我收到了 Stack Overflow 错误。我不知道为什么我会收到错误,而 Google 也没有提出任何建议。谢谢你的帮助。
import java.util.Scanner;
public class Account {
private int id;
private double balance;
private Scanner input = new Scanner(System.in);
private Account[] atm = new Account[10];
public Account(){
id = 0;
balance = 0;
for (int i = 0; i < atm.length; i++){
atm[i] = new Account(); //Here is where Eclipse says the problem is
atm[i].setID(i);
atm[i].setBalance(100.0);
}
}