📜  Java |继承|问题5

📅  最后修改于: 2021-06-28 21:32:42             🧑  作者: Mango

以下Java程序的输出?

class Base {
    public void Print() {
        System.out.println("Base");
    }         
}
  
class Derived extends Base {    
    public void Print() {
        System.out.println("Derived");
    }
}
  
class Main{
    public static void DoPrint( Base o ) {
        o.Print();   
    }
    public static void main(String[] args) {
        Base x = new Base();
        Base y = new Derived();
        Derived z = new Derived();
        DoPrint(x);
        DoPrint(y);
        DoPrint(z);
    }
}

(一种)

Base
Derived
Derived

(B)

Base
Base
Derived

(C)

Base
Derived
Base

(D)编译器错误答案: (A)
说明:请参阅https://www.geeksforgeeks.org/output-of-java-program-set-2/的问题1
这个问题的测验