10. interface Foo {  11. int bar();  12. }  13.  14. public 

题目
多选题
10. interface Foo {  11. int bar();  12. }  13.  14. public class Beta {  15.  16. class A implements Foo {  17. public int bar() { return 1; }  18. }  19.  20. public int fubar( Foo foo) { return foo.bar(); }  21.  22. public void testFoo() {  23.  24. class A implements Foo {  25. public int bar() { return 2; }  26. }  27.  28. System.out.println( fubar( new A())); 29. }  30.  31. public static void main( String[] argv) {  32. new Beta().testFoo();  33. }  34. }  Which three statements are true?()
A

Compilation fails.

B

The code compiles and the output is 2.

C

If lines 16, 17 and 18 were removed, compilation would fail.

D

If lines 24, 25 and 26 were removed, compilation would fail.

E

If lines 16, 17 and 18 were removed, the code would compile and the output would be 2.

F

If lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

参考答案和解析
正确答案: A,E
解析: 暂无解析
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

11. public void addStrings(List list) {  12. list.add(”foo”);  13. list.add(”bar”);  14. }  What must you change in this method to compile without warnings?() 

  • A、 add this code after line 11: list = (List) list;
  • B、 change lines 12 and 13 to: list.add(”foo”); list.add(”bar”);
  • C、 change the method signature on line 11 to: public void addStrings(List< extends String> list) {
  • D、 change the method signature on line 11 to: public void addStrings(List< super String> list) {
  • E、 No changes are necessary. This method compiles without warnings.

正确答案:D

第2题:

11. public interface Status {  12. /* insert code here */ int MY_VALUE = 10;  13. }  Which three are valid on line 12?()

  • A、 final
  • B、 static
  • C、 native
  • D、 public
  • E、 private
  • F、 abstract
  • G、 protected

正确答案:A,B,D

第3题:

Given:Which code, inserted at line 15, allows the class Sprite to compile?()

A.Foo { public int bar() { return 1; }

B.new Foo { public int bar() { return 1; }

C.new Foo() { public int bar() { return 1; }

D.new class Foo { public int bar() { return 1; }


参考答案:C

第4题:

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. // insert code here  17. }  18. }  Which code, inserted at line 16, correctly retrieves a local instance of a Point object?() 

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

正确答案:D

第5题:

10. interface Foo {}  11. class Alpha implements Foo {}  12. class Beta extends Alpha {}  13. class Delta extends Beta {  14. public static void main( String[] args) {  15. Beta x = new Beta();  16. // insert code here  17. }  18. }  Which code, inserted at line 16, will cause a java.lang.ClassCastException?() 

  • A、 Alpha a = x;
  • B、 Foo f= (Delta)x;
  • C、 Foo f= (Alpha)x;
  • D、 Beta b = (Beta)(Alpha)x;

正确答案:B

第6题:

11. public class Test {  12. public void foo() {  13. assert false;  14. assert false;  15. }  16. public void bar(){  17. while(true){  18. assert false;  19. }  20. assert false;  21. }  22. }  What causes compilation to fail?()  

  • A、 Line 13
  • B、 Line 14
  • C、 Line 18
  • D、 Line 20

正确答案:D

第7题:

10. public class Hello {  11. String title;  12. int value;  13. public Hello() {  14. title += “ World”;  15. }  16. public Hello(int value) {  17. this.value = value;  18. title = “Hello”;  19. Hello();  20. }  21. }  and:  30. Hello c = new Hello(5);  31. System.out.println(c.title);  What is the result?() 

  • A、 Hello
  • B、 Hello World
  • C、 Compilation fails.
  • D、 Hello World 5
  • E、 The code runs with no output.
  • F、 An exception is thrown at runtime.

正确答案:C

第8题:

10. public class ClassA {  11. public void count(int i) {  12. count(++i);  13. }  14. }  And:  20. ClassA a = new ClassA();  21. a.count(3);  Which exception or error should be thrown by the virtual machine?() 

  • A、 StackOverflowError
  • B、 NullPointerException
  • C、 NumberFormatException
  • D、 IllegalArgumentException
  • E、 ExceptionlnlnitializerError

正确答案:A

第9题:

public class Foo {  public int a;  public Foo() { a = 3; }  public void addFive() { a += 5; }  }  and:  public class Bar extends Foo { public int a;  public Bar() { a = 8; }  public void addFive() { this.a +=5; }  }  invoked with:  Foo foo = new Bar();  foo.addFive();  System.out.println(”Value: “+ foo.a);  What is the result?() 

  • A、 Value: 3
  • B、 Value: 8
  • C、 Value: 13
  • D、 Compilation fails.
  • E、 The code runs with no output.
  • F、 An exception is thrown at runtime.

正确答案:A

第10题:

Given:   10. class One {   11. void foo() { }   12. }   13. class Two extends One {   14. //insert method here   15. }   Which three methods, inserted individually at line 14, will correctly complete class Two?()

  • A、 public void foo() { /* more code here */ }
  • B、 private void foo() { /* more code here */ }
  • C、 protected void foo() { /* more code here */ }
  • D、 int foo() { /* more code here */ }  
  • E、 void foo() { /* more code here */ }

正确答案:A,C,E

更多相关问题