static int x;
这是的变量是不是有默认值????
就是这样
class Test{
static int x;
static void sop(){
System.out.println(x);
}
public static void main(String[] args){
Test t = new Test();
t.sop();
}
}
这个调用SOP能打印出x的值 是0 我就想问问这个0是怎么回事
全局变量在类被加载的时候就会赋于默认值吗??
追答不是全局变量会被赋予默认值,而是类的属性会被赋予默认值,也就是那些定义在类内部、方法外部的变量,不管是不是static,都会被赋值
本回答被提问者采纳