From the perspective of learning about the language, here in the "Beginning Java" forum, I wanted to make sure the OP did not think that overriding toString() was the only way to use System.out.println(), or even that it was the preferred or common way. That would be one interpretation of what you are saying.
I said that you would not have to override toString() in this case; perhaps I should have been more explicit and said "You would not have to override toString() to produce the specific output you want".
It is also arguable that your suggestion for "toString()" does not "textually represent" the BankAccount object. Depending on the needs of the application, just returning the account number *might* be fine, but might not be enough, and might be the wrong
string, etc.
But we can answer the OP's question without going into all that -- he/she wanted to know about using println to print the account number. The question implies that he does not understand how to extract field values from an object to have them printed by println(). Yours is one way to do that, and mine is another perfectly legitimate (and more flexible) way to do that.
The OP was not asking about overriding toString(), and I think it is misleading to imply that he is supposed to
for this purpose. I said nothing about whether he "should" override toString(). I daresay most of the
java classes I've seen do not, and I think it is misleading to tell a newish programmer that he should do so to get println output. If later he wants to output the account holder's name as well, but still have this statement work this way, would you tell him to put a flag variable in the class so he can set it so that toString() will give him the 'right' string?