// "pass by reference" DIS // How do you "pass an object"? technically, by value, but what you're // really passing the reference value, which is the address of the // object. A call to the method stores the address of the object in // the formal parameter of the method. class Data1 { int k; } class Test1 { void change(Data1 x) { System.out.println("Before changing: " + x.k); x.k++; System.out.println("After changing: " + x.k); } } public class pass1 { public static void main(String[] args) { Test1 t = new Test1(); Data1 d = new Data1(); d.k = 1; System.out.println("Before passing: " + d.k); t.change(d); System.out.println("After passing: " + d.k); } } /* output: Before passing: 1 Before changing: 1 After changing: 2 After passing: 2 */