在全局变量中使用才能输出,而在方法中是必须初始化的,必须给其赋值,否则会报错!
public class IntDemo {
public static void main(String[] args) {
int a;
System.out.println("a = " + a); //报错!
}
}
这种定义在类中的变量就能够输出默认值0;
public class IntDemo {
static int a;
public static void main(String[] args) {
System.out.println("a = " + a);
}
}
Integer类型也是一样的道理。