Get the program here
1:/*
2:Before method1, acc is :
3:Name: Charles
4:Saving: 1000
5:
6:Aafter method1, acc is :
7:Name: Charles
8:Saving: 1000
9:
10:Before method2, acc is :
11:Name: Charles
12:Saving: 1000
13:
14:Aafter method2, acc is :
15:Name: Charles
16:Saving: 2000
17:*/
18:public class PassByReferTest {
19: public static void main(String[] args) {
20: BankAccount acc = new BankAccount("Charles", 1000);
21: System.out.println("Before method1, acc is :\n" + acc.showInfo());
22: method1(acc);
23: System.out.println();
24: System.out.println("After method1, acc is :\n" + acc.showInfo());
25: System.out.println();
26: System.out.println("Before method2, acc is :\n" + acc.showInfo());
27: method2(acc);
28: System.out.println();
29: System.out.println("After method2, acc is :\n" + acc.showInfo());
30:
31: }
32:
33: public static void method1(BankAccount a) {
34: a = new BankAccount("Amy");
35: }
36:
37: public static void method2(BankAccount a) {
38: a.deposit(1000);
39: }
40:}