单项选择题
class Bird {
static void talk() { System.out.print("chirp "); }
}
class Parrot extends Bird {
static void talk() { System.out.print("hello "); }
public static void main(String [] args) {
Bird [] birds = {new Bird(), new Parrot()};
for( Bird b : birds)
b.talk();
}
}
结果为:()
A.chirp chirp
B.chirp hello
C.hello hello
D.编译失败
点击查看答案&解析
相关考题
-
单项选择题
现有: 1. interface Animal { 2. void eat(); 3. } 4. 5. // insert code here 6. 7. public class HouseCat extends Feline { 8. public void eat() { } 9. } 和五个声明: abstract class Feline implements Animal { } abstract class Feline implements Animal { void eat(); } abstract class Feline implements Animal { public void eat(); } abstract class Feline implements Animal { public void eat() { } } abstract class Feline implements Animal { abstract public void eat(); } 分别插入到第5行,有几个可以通过编译?()
A.0
B.1
C.2
D.3 -
单项选择题
现有: class Cat { Cat(int c) { System.out.print("cat" + c + " "); } } class SubCat extends Cat { SubCat(int c) { super(5); System.out.print("cable "); } SubCat() { this(4); } public static void main(String [] args) { SubCat s = new SubCat(); } } 结果为:()
A.cat5
B.cable
C.cable cat5
D.cat5 cable -
单项选择题
class Dog { } class Harrier extends Dog { } class DogTest { public static void main(String [] args) { Dog d1 = new Dog(); Harrier h1 = new Harrier(); Dog d2 = h1; Harrier h2 = (Harrier) d2; Harrier h3 = d2; } } 下面哪一项是正确的?()
A.编译失败
B.2个Dog对象被创建
C.2个Harrier对象被创建
D.3个Harrier对象被创建
