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來修飾。