多选题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?()ACompilation fails.BThe code compiles and the output is 2.CIf lines 16, 17 and 18 were removed, compilation would fail.DIf lines 24, 25 and 26 were removed, compilation would fail.EIf lines 16, 17 and 18 were removed, the code would compile and the output would be 2.FIf lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

多选题
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.


参考解析

解析: 暂无解析

相关考题:

( 10 )已知下列程序的输出结果是 42 ,请将画线处缺失的部分补充完整。#includeusing namespace std;class Foo {int value;public:Foo( ) : value(0) {}void setValue(int value){ 【 10 】 = value; // 给 Foo 的数据成员 value 赋值 }void print( ) { cout value; }};int main( ){Foo f;f.setValue(42);f.print();return 0;}

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; }

10. interface Foo { int bar(); }  11. public class Sprite {  12. public int fubar( Foo foo) { return foo.bar(); }  13. public void testFoo() {  14. fubar(  15. // insert code here  16.);  17. }  18. }  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、 newFoo() { public int bar(){return 1; } }D、 new class Foo { public int bar() { return 1; } }

class Foo {  private int x;  publicFoo(intx) {this.x=x; }  public void setX( int x) { this.x = x; }  public int getX() { return x; }  }   public class Gamma {  static Foo fooBar( Foo foo) {  foo = new Foo( 100);  return foo;  }  public static void main( String[] args) {  Foo foo = new Foo( 300);  System.out.print( foo.getX() + “-“);  Foo fooFoo = fooBar( foo);  System.out.print( foo.getX() + “-“);  System.out.print( fooFoo.getX() + “-“);  foo = fooBar( fooFoo);  System.out.print( foo.getX() + “-“);  System.out.prmt( fooFoo.getX());  }  }  What is the output of this program?()A、 300-100-100-100-100B、 300-300-100-100-100C、 300-300-300-100-100D、 300-300-300-300-100

1. package foo;  2.    3. import java.util.Vector;  4.    5. private class MyVector extends Vector {  6. int i = 1;  7. public MyVector()  {  8. i = 2;  9.    }  10. }  11.    12. public class MyNewVector extends MyVector {  13. public MyNewVector ()  {  14. i = 4;  15. }  16. public static void main (String args [])  {  17. MyVector v = new MyNewVector();  18.   }  19. }     The file MyNewVector.java is shown in the exhibit.  What is the result?()  A、 Compilation will succeed.B、 Compilation will fail at line 5.C、 Compilation will fail at line 6.D、 Compilation will fail at line 14.E、 Compilation will fail at line 17.

1. public class Test { 2. public static String output =””; 3.  4. public static void foo(int i) { 5. try { 6. if(i==1) { 7. throw new Exception(); 8. } 9. output += “1”; 10. } 11. catch(Exception e) { 12. output += “2”; 13. return; 14. } 15. finally { 16. output += “3”;17. } 18. output += “4”; 19. } 20.  21. public static void main(String args[]) { 22. foo(0); 23. foo(1); 24.  25. }26. } What is the value of the variable output at line 23?()

class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()A、 public void foo() { }B、 public int foo() { return 3; }C、 public Two foo() { return this; }D、 public One foo() { return this; }E、 public Object foo() { return this; }

public class Delta {  static boolean foo(char c) {  System.out.print(c);  return true;  }  public static void main( String[] argv ) {  int i =0;  for ( foo(‘A’); foo(‘B’)(i2); foo(‘C’)){  i++ ;  foo(‘D’);  }  }  }  What is the result?()  A、 ABDCBDCBB、 ABCDABCDC、 Compilation fails.D、 An exception is thrown at runtime.

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 13B、 Line 14C、 Line 18D、 Line 20

public class Test {  public static void main(String args[]) {  class Foo {  public int i = 3; }  Object o = (Object)new Foo();   Foo foo = (Foo)o;  System.out.println(“i = “ + foo.i); }  }  What is the result?()  A、 i = 3B、 Compilation fails.C、 A ClassCastException is thrown at line 6.D、 A ClassCastException is thrown at line 7.

public class Foo {  private int val;  public foo(int v) (val = v;)  }  public static void main (String [] args)  {  Foo a = new Foo (10);  Foo b = new Foo (10);  Foo c = a;  int d = 10;  double e = 10.0;  }  Which three logical expression evaluate to true?()A、 (a ==c)B、 (d ==e)C、 (b ==d)D、 (a ==b)E、 (b ==c)F、 (d ==10.0)

10. public class Foo implements java.io.Serializable {  11. private int x;  12. public int getX() { return x; }  12.publicFoo(int x){this.x=x; }  13. private void writeObject( ObjectOutputStream s)  14. throws IOException {  15. // insert code here  16. }  17. }  Which code fragment, inserted at line 15, will allow Foo objects to be correctly serialized and deserialized?() A、 s.writeInt(x);B、 s.serialize(x);C、 s.writeObject(x);D、 s.defaultWriteObject();

1. public class test {  2. public static string output = “”  3.    4. public static void foo(int i) {  5. try {  6. if(i= =1) {  7. throw new Exception ();  8. }  9. output += “1”;  10.}  11. catch(Exception e)  {  12. output += “2”;  13. return;  14.}  15. finally (  16. output += “3”;  17. )  18. output += “4”;  19. } 20.    21. public static void main (string args[])  (  22. foo(0);  23. foo(1);  24.    25. )  26. } What is the value of the variable output at line 24?()

10. class Inner {  11. private int x;  12. public void setX( int x) { this.x = x; }  13. public int getX() { return x; }  14. }  15.  16. class Outer {  17. private Inner y;  18. public void setY( Inner y) { this.y = y; }  19. public Inner getY() { return y; }  20. }  21.  22. public class Gamma {  23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner();  26.int n=10;  27. i.setX(n);  28. o.setY(i);  29. // insert code here  30. System.out.println( o.getY().getX());  31. }  32. }  Which three code fragments, added individually at line 29, produce the output 100?()A、 n = 100;B、 i.setX( 100);C、 o.getY().setX( 100);D、 i = new Inner(); i.setX( 100);E、 o.setY( i); i = new Inner(); i.setX( 100);F、 i = new Inner(); i.setX( 100); o.setY( i);

1. import java.io.*;  2. public class Foo implements Serializable {  3. public int x, y;  4. public Foo( int x, int y) { this.x = x; this.y = y; }  5.  6. private void writeObject( ObjectOutputStream s)  7. throws IOException {  8. s.writeInt(x); s.writeInt(y)  9. }  10.  11. private void readObject( ObjectInputStream s)  12. throws IOException, ClassNotFoundException {  13.  14. // insert code here  15.  16. }  17. }  Which code, inserted at line 14, will allow this class to correctly serialize and deserialize?() A、 s.defaultReadObject();B、 this = s.defaultReadObject();C、 y = s.readInt(); x = s.readInt();D、 x = s.readInt(); y = s.readInt();

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;

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.

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: 3B、 Value: 8C、 Value: 13D、 Compilation fails.E、 The code runs with no output.F、 An exception is thrown at runtime.

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 */ }

多选题10. class Inner {  11. private int x;  12. public void setX( int x) { this.x = x; }  13. public int getX() { return x; }  14. }  15.  16. class Outer {  17. private Inner y;  18. public void setY( Inner y) { this.y = y; }  19. public Inner getY() { return y; }  20. }  21.  22. public class Gamma {  23. public static void main( String[] args) { 24. Outer o = new Outer(); 25. Inner i = new Inner();  26.int n=10;  27. i.setX(n);  28. o.setY(i);  29. // insert code here  30. System.out.println( o.getY().getX());  31. }  32. }  Which three code fragments, added individually at line 29, produce the output 100?()An = 100;Bi.setX( 100);Co.getY().setX( 100);Di = new Inner(); i.setX( 100);Eo.setY( i); i = new Inner(); i.setX( 100);Fi = new Inner(); i.setX( 100); o.setY( i);

单选题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;

单选题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: 3B Value: 8C Value: 13D Compilation fails.E The code runs with no output.F An exception is thrown at runtime.

单选题public class Delta {  static boolean foo(char c) {  System.out.print(c);  return true;  }  public static void main( String[] argv ) {  int i =0;  for ( foo(‘A’); foo(‘B’)(i2); foo(‘C’)){  i++ ;  foo(‘D’);  }  }  }  What is the result?()A ABDCBDCBB ABCDABCDC Compilation fails.D An exception is thrown at runtime.

单选题public class Test {  public static void main(String args[]) {  class Foo {  public int i = 3; }  Object o = (Object)new Foo();   Foo foo = (Foo)o;  System.out.println(“i = “ + foo.i); }  }  What is the result?()A i = 3B Compilation fails.C A ClassCastException is thrown at line 6.D A ClassCastException is thrown at line 7.

多选题public class Foo {  private int val;  public foo(int v) (val = v;)  }  public static void main (String [] args)  {  Foo a = new Foo (10);  Foo b = new Foo (10);  Foo c = a;  int d = 10;  double e = 10.0;  }  Which three logical expression evaluate to true?()A(a ==c)B(d ==e)C(b ==d)D(a ==b)E(b ==c)F(d ==10.0)

多选题class One {   public One foo() { return this; }  }  class Two extends One {  public One foo() { return this; }  }  class Three extends Two {   // insert method here  }  Which two methods, inserted individually, correctly complete the Three class?()Apublic void foo() { }Bpublic int foo() { return 3; }Cpublic Two foo() { return this; }Dpublic One foo() { return this; }Epublic Object foo() { return this; }

多选题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?()ACompilation fails.BThe code compiles and the output is 2.CIf lines 16, 17 and 18 were removed, compilation would fail.DIf lines 24, 25 and 26 were removed, compilation would fail.EIf lines 16, 17 and 18 were removed, the code would compile and the output would be 2.FIf lines 24, 25 and 26 were removed, the code would compile and the output would be 1.

单选题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 13B Line 14C Line 18D Line 20