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); } }
编译成功。