Primitive Type
public class Counter {
public int count = 0;
}
public class Updater {
public void update(int count) {
count += 1;
}
}
public class Main {
public static void main(String[] args) {
Counter c = new Counter();
System.out.println("before update : " + c.count);
Updater u = new Updater();
u.update(c.count);
System.out.println("after update : " + c.count);
}
}
Reference Type
public class Updater {
public void update(Counter counter) {
counter.count += 1;
}
}
public class Main {
public static void main(String[] args) {
Counter c = new Counter();
System.out.println("before update : " + c.count);
Updater u = new Updater();
u.update(c);
System.out.println("after update : " + c.count);
}
}