Given:

package p1;

public class Test {

    static double dvalue;
    static Test ref;

    public static void main(String[] args) {
        System.out.println(ref);
        System.out.println(dvalue);
    }
}

What is the result?

A.

p1.Test.class
0.0

B

<the summary address refrenced by ref>
0.000000

C.

null
0.0

D. Compilation fails
E. A NullPointerException is thrown at runtime

题解

dvalue 和 ref 是 Test 的类别变量,在声明时就会自动被初始化。dvalue 的型态为 double,会被初始化为 0。ref 的型态为 Test,为对象参考型态,会被初始化为 null。

println 方法若传入的参考为 null,会直接输出「null」。

因此这题答案是选项 C。