java中的变量未初始化,会出现什么问题呢,如果是基本数据类型,则会有初始值,如果不是,则一般是null,以下为测试结果
public class Test {
String str;
int a;
char b;
short s;
float f;
long lo;
double dou;
byte e;
boolean flag;
Object obj;
public static void main(String[] args){
Test ts = new Test();
ts.print();
}
public void print(){
System.out.println("str:"+str+"\n"+"a:"+a+"\n"+"b:"+b+"\n"+"s:"+s+"\n"+"f:"+f+"\n"+"lo:"+lo+"\n"+"dou:"+dou
+ "\n"+"e:"+e+"\n"+"flag:"+flag+"\n"+"obj:"+obj+"\n");
}
}
输出结果为
str:null
a:0
b:
s:0
f:0.0
lo:0
dou:0.0
e:0
flag:false
obj:null