Given the code fragment:

abstract class Planet {

    protected void revolve() { // line n1

    }

    abstract void rotate(); // line n2
}

class Earth extends Planet {

    void revolve() { // line n3

    }

    protected void rotate() { // line n4

    }
}

Which two modifications, made independently, enable the code to compile?

A. Make the method at line n1 public.
B. Make the method at line n2 public.
C. Make the method at line n3 public.
D. Make the method at line n3 protected.
E. Make the method at line n4 public.

题解

题目原本提供的程序会在 line n3 编译错误,原因在于 Earth 类别继承的 Planet 类别,其 revolve 方法的可见度使用 protected 来修饰。若要在 Earth 类别覆写 revolve 方法,其可见度必须不能小于 protected,因此 Earth 类别的 revolve 方法的可见度只能用 protected 或是 public 来修饰。