为什么没有将默认值分配给尚未在具有主函数的类中初始化的变量???
class Test {
public static void main(String[] args) {
int x;// x has no default value
String y;// y has no default value
System.out.println("x is " + );
System.out.println("y is " + );
}
}
而在没有任何主函数的类中变量保持未初始化的情况下,会分配默认值。
class Student {
String name; // name has default value null
int age; // age has default value 0
boolean isScienceMajor; // isScienceMajor has default value false
char gender; // c has default value '\u0000'
int x;
String y;
}