给出以下代码:31.class Foo {32.public int a = 3;33.public void addFive() { a += 5; System.out.print("f "); }34. }35.class Bar extends Foo {36.public int a = 8;37.public void addFive() { this.a += 5; System.out.print("b " ); }38. }执行以下语句后的结果是什么?Foo f = new Bar(); f.addFive(); System.out.println(f.a);提示:调用方法的时候看new后面是哪个类?调用属性的时候看对象的类型是谁?
A.b 3
B.b 8
C.b 13
D.f 3
E.f 8
F.f 13
查看答案
给出以下代码:11. class Animal { public String noise() {return "peep"; } }12. class Dog extends Animal {13. public String noise() { return "bark"; }14. }15. class Cat extends Animal {16. public String noise() { return "meow"; }17. } ...30. Animal animal = new Dog();31. Cat cat = (Cat)animal;32. System.out.println(cat.noise());请问程序的执行结果是什么?
A.peep
B.bark
C.meow
D.编译失败
E.执行时发生ClassCastException
为了区分重载多态中同名的不同方法,要求()。
A. 采用不同的参数列表
B. 返回值类型不同
C. 调用时用类名或对象名做前缀
D. 参数名不同
定义主类的类头时可以使用的访问修饰符是()。
A.private
B.protected
C.public
D.private protected
以下代码:11. public interface Status {12. /* 这里可以填什么 */ int MY_VALUE = 10;13. }以下选三项().
A.final
B.static
C.native
D.public
E.private
F.abstract
G.protected