Given:

class Caller {

    private void init() {
        System.out.println("Initialized");
    }

    public void start() {
        init();
        System.out.println("Started");
    }
}

public class TestCall {

    public static void main(String[] args) {
        Caller c = new Caller();
        c.start();
        c.init();
    }
}

What is the result?

A.

Initialized
Started

B.

Initialized
Started
Initialized

C. Compilation fails
D. An exception is thrown at runtime

题解

程序第 18 行使用了 Caller 对象的 init 方法。由于 init 方法被 private 修饰字修饰,它的可见度只有在 Caller 这个类别之内,所以 TestCall 类别无法去调用到 Caller 对象的 init 方法,会在编译时出现错误。