集册 Java实例教程 说明函数如何更改静态变量

说明函数如何更改静态变量

欢马劈雪     最近更新时间:2020-01-02 10:19:05

383
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
说明函数如何更改静态变量
/*时 代 J     a    v  a - nowjava.com*/

public class Main {

  static int x = 0;


  static void F()

  {

    x++;

  }


  static void G() {

    --x;

  }


  public static void main(String[] args) {

    F(); // x=1/*nowjava.com*/

    G(); // x=0

    F(); // x=1

    System.out.println("value of x:" + x);

  }

}