下面是两个典型例子:

public class SystemDemo {
  int i;
  public static void main(String[] args) {
    char inputChar;
    int i;
    System.out.println(i);
      }
}

编译时出现以下错误信息:
SystemDemo.java:11: variable i might not have been initialized
System.out.println(i);
^
1 error


修改代码如下:
public class SystemDemo {
  int i;
  public static void main(String[] args) {
    /*
     * 测试系统读入键盘数据
     */
        SystemDemo sd = new SystemDemo();
    System.out.println(sd.i);
  }
}

编译成功。
posted on 2005-02-08 16:41  Johnny  阅读(600)  评论(0编辑  收藏  举报