【发布时间】:2013-09-01 12:02:31
【问题描述】:
我有以下代码:
public class StaticKindOfThing {
static int a =getValue();
static int b = 10;
public static int getValue()
{
return b;
}
public static void main (String []args)
{
System.out.println(a);
}
}
我知道默认变量设置为 0,但它不会在运行时发生吗?从上面的代码看来,默认初始化为 0 发生在运行时之前。否则 getValue 应该给出编译错误或运行时异常,找不到该值。
所以我的问题是。变量static int b = 10;在编译时是否得到默认值0?
【问题讨论】:
标签: java class static-members