You're correct, variable names are unique in its given scope (local in-method vs. instance variable). Nevertheless, as this is object-oriented you can reuse the variable as it only references a given object:
List<Account> accountList = new ArrayList<Account>();
// creditaccount
Account account = new CreditAccount();
list.add(account); // <-- adds the creditAccount to the list
// savingsaccount
account = new SavingsAccount(); // <-- reuse account
list.add(account); // <-- adds the savingsAccount to the list
Personally, I do not like that approach and rather use self-explanatory names like:
Account creditAccount = new CreditAccount();
Account savingsAccount = new SavingsAccount();
...
list.add(creditAccount);
list.add(savingsAccount);
UPDATE 1:
If you do not have to further initialize the account objects you could just do this:
list.add(new CreditAccount());
list.add(new SavingsAccount());
UPDATE 2:
I forgot to mention that there is a 'more advanced' approach using anonymous inner blocks, enabling you to declare a variable more than once inside a method:
void someMehtod() {
List<Account> accountList = new ArrayList<Account>();
{ // <-- start inner block
Account account = new CreditAccount();
accountList.add(account);
} // <-- end inner block
{
Account account = new SavingsAccount();
accountList.add(account);
}
account.toString() // compile time error as account is not visible!
}