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

相关考题:

Given: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. class Foo {  11. static void alpha() { /* more code here */ }  12. void beta() { /* more code here */ }  13. }  Which two are true?()A、 Foo.beta() is a valid invocation of beta().B、 Foo.alpha() is a valid invocation of alpha().C、 Method beta() can directly call method alpha().D、 Method alpha() can directly call method beta().

class One {  void foo() {}  }  class Two extends One {   //insert method here  }  Which three methods, inserted individually at line 14, will correctly complete class Two?()A、 int foo() { /* more code here */ }B、 void foo() { /* more code here */ }C、 public void foo() { /* more code here */ }D、 private void foo() { /* more code here */ }E、 protected void foo() { /* more code here */ }

10. class Line {  11. public static class Point { }  12. }  13.  14. class Triangle {  15. // insert code here  16. }  Which code, inserted at line 15, creates an instance of the Point class defined in Line?() A、 Point p = new Point();B、 Line.Point p = new Line.Point();C、 The Point class cannot be instatiated at line 15.D、 Line 1 = new Line() ; 1.Point p = new 1.Point();

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

11. public class Counter {  12. public static void main(String[] args) {  13. int numArgs = /* insert code here */;  14. }  15. }  and the command line: java Counter one fred 42 Which code, inserted at line 13, captures the number of arguments passed into the program?() A、 args.countB、 args.lengthC、 args.count()D、 args.length()E、 args.getLength()

11. static class A {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B”); }  16. }  17. public static void main(String[] args) {  18. new B().process();  19. }  What is the result?() A、 BB、 The code runs with no output.C、 Compilation fails because of an error in line 12.D、 Compilation fails because of an error in line 15.E、 Compilation fails because of an error in line 18.

1. class Alpha { void m1() {} }   2. class Beta extends Alpha { void m2() { } }   3. class Gamma extends Beta { }   4.   5. class GreekTest {   6. public static void main(String [] args) {   7. a Alpha [] a = {new Alpha(), new Beta(), new Gamma() };   8. for(Alpha a2 : a) {   9. a2.m1();   10. if (a2 instanceof Beta || a2 instanceof Gamma)   11. //insert code here   12. }   13. }   14. }   哪一行代码插入到第11行,将编译但是会在运行时产生异常?()  A、 a2.m2();B、 ((Beta)a2).m2();C、 ((Alpha)a2).m2();D、 ((Gamma)a2).m2();

package sun.scjp;  public enum Color { RED, GREEN, BLUE }  package sun.beta;  // insert code here  public class Beta {  Color g = GREEN;  public static void main( String[] argv)  { System.out.println( GREEN); }  }  The class Beta and the enum Color are in different packages.  Which two code fragments, inserted individually at line 2 of the Beta declaration, will allow this code to compile?()A、 import sun.scjp.Color.*;B、 import static sun.scjp.Color.*;C、 import sun.scjp.Color; import static sun.scjp.Color.*;D、 import sun.scjp.*; import static sun.scjp.Color.*;E、 import sun.scjp.Color; import static sun.scjp.Color.GREEN;

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();

interface Beta {}  class Alpha implements Beta {  String testIt() {  return “Tested”;  }  }  public class Main1 {  static Beta getIt() {  return new Alpha();  }  public static void main( String[] args ) {  Beta b = getIt();  System.out.println( b.testIt() );  }  }  What is the result?()  A、 TestedB、 Compilation fails.C、 The code runs with no output.D、 An exception is thrown at runtime.

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. 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();

Given:   11. static class A {   12. void process() throws Exception { throw new Exception(); }   13. }   14. static class B extends A {   15. void process() { System.out.println("B "); }   16. }   17. public static void main(String[] args) {   18. A a = new B();   19. a.process();   20. }   What is the result? ()A、 Compilation fails because of an error in line 19.B、 An exception is thrown at runtime.C、 BD、 Compilation fails because of an error in line 18.E、 Compilation fails because of an error in line 15. F、 The code runs with no output.

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

多选题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?()Apublic void foo() { /* more code here */ }Bprivate void foo() { /* more code here */ }Cprotected void foo() { /* more code here */ }Dint foo() { /* more code here */ }Evoid foo() { /* more code here */ }

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

单选题interface Beta {}  class Alpha implements Beta {  String testIt() {  return “Tested”;  }  }  public class Main1 {  static Beta getIt() {  return new Alpha();  }  public static void main( String[] args ) {  Beta b = getIt();  System.out.println( b.testIt() );  }  }  What is the result?()A TestedB Compilation fails.C The code runs with no output.D An exception is thrown at runtime.

单选题11. public class Counter {  12. public static void main(String[] args) {  13. int numArgs = /* insert code here */;  14. }  15. }  and the command line: java Counter one fred 42 Which code, inserted at line 13, captures the number of arguments passed into the program?()A args.countB args.lengthC args.count()D args.length()E args.getLength()

单选题1. import java.util.*;  2. class SubGen {  3. public static void main(String [] args) {  4. //insert code here  5. }  6. }  class Alpha { }  class Beta extends Alpha { }  class Gamma extends Beta { }  和四段代码片段:  s1. ArrayList〈? extends Alpha〉 list1 = new ArrayList〈Gamma〉();  s2. ArrayList〈Alpha〉 list2 = new ArrayList〈? extends Alpha〉();  s3. ArrayList〈? extends Alpha〉 list3 = new ArrayList〈? extends Beta〉();  s4. ArrayList〈? extends Beta〉 list4 = new ArrayList〈Gamma〉(); ArrayList〈? extends Alpha〉 list5 = list4;  哪些片段分别插入到第4行,可允许代码编译?()A只有s1B只有s3C只有s1和s3D只有s1和s4

单选题11. static class A {  12. void process() throws Exception { throw new Exception(); }  13. }  14. static class B extends A {  15. void process() { System.out.println(”B”); }  16. }  17. public static void main(String[] args) {  18. new B().process();  19. }  What is the result?()A BB The code runs with no output.C Compilation fails because of an error in line 12.D Compilation fails because of an error in line 15.E Compilation fails because of an error in line 18.

单选题现有:   1.  class Alpha { void m1() {} }   2.  class Beta extends Alpha { void m2() { } }   3.  class Gamma extends Beta { }   4.   5.  class GreekTest {   6.    public static void main(String [] args) {   7.      Alpha [] a = {new Alpha(), new Beta(), new Gamma() };   8.      for(Alpha a2 : a) {   9.        a2.m1();    10.       if (a2 instanceof Beta || a2 instanceof Gamma)    11.         //insert code here   12.     }    13.   }   14. }    哪一行代码插入到第11行,将编译但是会在运行时产生异常?()A a2.m2();B ((Beta)a2).m2();C ((Alpha)a2).m2();D ((Gamma)a2).m2();

多选题class One {  void foo() {}  }  class Two extends One {   //insert method here  }  Which three methods, inserted individually at line 14, will correctly complete class Two?()Aint foo() { /* more code here */ }Bvoid foo() { /* more code here */ }Cpublic void foo() { /* more code here */ }Dprivate void foo() { /* more code here */ }Eprotected void foo() { /* more code here */ }

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

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

单选题Which statements, when inserted at the indicated position in the following code, will cause a runtime exception when attempting to run the program?()   class A {}   class B extends A {}   class C extends A {}   public class Q3ae4 {   public static void main(String args[]) {   A x = new A();   B y = new B();   C z = new C();   // insert statement here   }   }Ax = y;Bz = x;Cy = (B) x;Dz = (C) y;Ey = (A) y;

多选题10. class Foo {  11. static void alpha() { /* more code here */ }  12. void beta() { /* more code here */ }  13. }  Which two are true?()AFoo.beta() is a valid invocation of beta().BFoo.alpha() is a valid invocation of alpha().CMethod beta() can directly call method alpha().DMethod alpha() can directly call method beta().