public class testMain { static int x; static int y; public static void main(String[] args) { x = 0; y = 0; System.out.println("x:"+x+" y:"+y); x++; System.out.println("x:"+x+" y:"+y); myMethod(); System.out.println("x:"+x+" y:"+y); System.out.println(x + y + ++x); } public static void myMethod(){ y = x++ + ++x; } }
Result:
x:0 y:0
x:1 y:0
x:3 y:4
11