Java中数组的空指针异常

Bil*_*ill -3 java nullpointerexception

以下代码在Java中返回NullPointerException.谁能澄清我的错误?

public void deposit2()
{
    BankAccounts[] accounts2 = new BankAccounts[10];
    accounts2[3].deposit();
}
Run Code Online (Sandbox Code Playgroud)

And*_*ner 10

BankAccounts[] accounts2 = new BankAccounts[10];
Run Code Online (Sandbox Code Playgroud)

是相同的

BankAccounts[] accounts2 = {null, null, null, ... null };  // (10 times)
Run Code Online (Sandbox Code Playgroud)

accounts2在尝试取消引用它们之前,需要为元素(或至少对元素3)赋值.