public class Pet{ public void speak(){ System.out.print(“ Pet ”); } } public class Cat extends Pet{ public void speak(){ System.out.print(“ Cat ”); } } public class Dog extends Pet{ public void speak(){ System.out.print(“ Dog ”); } } 执行代码 Pet[] p = {new Cat(),new Dog(),new Pet()}; for(int i=0;i〈p.length;i++) p[i].speak(); 后输出的内容是哪项?()
A、Pet Pet Pet
B、Cat Cat Cat
C、Cat Dog Pet
D、Cat Dog Dog
相关问题推荐
-
在层次化网络设计中,(68)不是核心层交换机的设备选型策略。
A.高速数据转发
B.高可靠性
C.良好的可管理性
D.实现网络的访问策略控制
-
编写一个Java程序实现多线程,在线程中输出线程的名字,隔300毫秒输出一次,共输出20次。
-
已知:的输出为()
A、a
B、b
C、c
D、null
-
class Beta { public static void main(String [] args) { Integer x = new Integer(6) * 7; if (x != 42) { System.out.print("42 "); } else if (x 〈 new Integer(44-1)) { System.out.println("less"); } else { System.out.print("done"); } } } 结果是什么?()
A、less
B、42
C、done
D、编译失败
-
现有: class Pencil { public void write (String content){ System.out.println( "Write",+content){ } }class RubberPencil extends Pencil{ public void write (String content){ System.out.println("Rubber Write"+content); } public void erase (String content)}} 执行下列代码的结果是哪项?() Pencil pen=new Pencil(); (( RubberPencil) pen).write( "Hello");
A、Write Hello
B、Rubber Write Hello
C、编译失败
D、运行时抛出异常