Java examples for Object Oriented Design:Static
Illustrating how functions can change the static variable
public class Main { static int x = 0; static void F() {/*from ww w.j av a 2 s.c o m*/ x++; } static void G() { --x; } public static void main(String[] args) { F(); // x=1 G(); // x=0 F(); // x=1 System.out.println("value of x:" + x); } }