题目内容

给出以下代码:10.class Line {11. public class Point { public int x,y;}12. public Point getPoint() { return new Point(); }13. }14. class Triangle {15. public Triangle() {16. // 此处加入代码17. }18. }第16行加入以下哪一行代码,可以定义一个Point对象?

A.Point p = Line.getPoint();
B.Line.Point p = Line.getPoint();
C.Point p = (new Line()).getPoint();
D.Line.Point p = (new Line()).getPoint();

查看答案
更多问题

阅读以下代码11.class Alpha {12. public void foo() { System.out.print("Afoo "); }13. }14. public class Beta extends Alpha {15. public void foo() { System.out.print("Bfoo "); }16. public static void main(String[] args) {17. Alpha a = new Beta();18. Beta b = (Beta)a;19. a.foo();20. b.foo();21. }22. }程序的执行结果是?

A.Afoo Afoo
B.Afoo Bfoo
C.Bfoo Afoo
D.Bfoo Bfoo

给出以下代码: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. 参数名不同

答案查题题库