Here's an example:
public void switchAccount(Account account){ account.setCurrency("GBP"); account = new Account(); account.setAccountName("magnate"); } public static void main(String[] args){ Account account1 = new Account(); account1.setAccountName("indictment"); switchAccount(account1); System.out.println(account1.getAccountName()); System.out.println(account1.getCurrency()); }Since both copy refernce and original reference refer to account1, thereby the following line would take effect:
account.setCurrency("GBP");Although
account = new Account();gives the copy reference a new value(object address), the original reference remains intact, hence, account1's name would not change.
Reference:
1. The C Progmming Language. K&R
2. http://stackoverflow.com/questions/40480/is-java-pass-by-reference