Java examples for Object Oriented Design:Method Parameter
An Example of Pass by Constant Value
public class Main { // x uses pass by constant value and y uses pass by value public static void test(final int x, int y) { System.out.println("#2: x = " + x + ", y = " + y); y = 3; // Ok to change y System.out.println("#3: x = " + x + ", y = " + y); }/* w w w. j a va 2 s . c om*/ public static void main(String[] args) { int a = 1; int b = 3; System.out.println("#1: a = " + a + ", b = " + b); Main.test(a, b); System.out.println("#4: a = " + a + ", b = " + b); } }