// Example that shows that variables in different scopes // have no relation to one another even if they have the // same name. public class ReturnExample { public static void main(String[] args) { int x = 1; // "Use it or lose it". The return value is not // saved into a variable, used in another expression, // or outputted, so it gets lost. addOne(x); // This outputs 'x = 1'. Do you understand why? System.out.println("x = " + x); } // This method adds one to the parameter. This "x" // gets incremented by 1, but it has no relation to // the "x" in main. public static int addOne(int x) { x = x + 1; return x; } }