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


参考解析

解析: 暂无解析

相关考题:

ClicktheExhibitbutton.Given:11.%com.example.Advisoradvisor=newcom.example.Advisor();%12.%request.setAttribute(foo,advisor);%Assumingtherearenootherfooattributesinthewebapplication,whichthreearevalidELexpressionsforretrievingtheadvicepropertyofadvisor?()A.${foo.advice}B.${request.foo.advice}C.${requestScope.foo.advice}D.${requestScope[foo[advice]]}E.${requestScope[foo][advice]}

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

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

Which statements concerning the relationships between the following classes are true?()   class Foo {  int num;   Baz comp = new Baz();   }   class Bar {  boolean flag;   }   class Baz extends Foo {   Bar thing = new Bar();   double limit;   }  A、A Bar is a Baz.B、A Foo has a Bar.C、A Baz is a Foo.D、A Foo is a Baz.E、A Baz has a Bar.

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.

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;

1.public class Test {  2.public static void main (String args[]) {  3.class Foo {  4.public int i = 3;  5.}  6.Object o = (Object) new Foo();  7.Foo foo = (Foo)o;  8.System.out.printIn(foo. i); 9. }  10.}   What is the result?()  A、 Compilation will fail.B、 Compilation will succeed and the program will print “3”C、 Compilation will succeed but the program will throw a ClassCastException at line 6.D、 Compilation will succeed but the program will throw a ClassCastException at line 7.

interface foo {   int k = 0;   }    public class test implements Foo (   public static void main(String args) (    int i;   Test test = new test ();   i= test.k;   i= Test.k;   i= Foo.k;   )   )   What is the result? ()A、 Compilation succeeds.B、 An error at line 2 causes compilation to fail.C、 An error at line 9 causes compilation to fail.D、 An error at line 10 causes compilation to fail.E、 An error at line 11 causes compilation to fail.

单选题interface foo {   int k = 0;   }    public class test implements Foo (   public static void main(String args) (    int i;   Test test = new test ();   i= test.k;   i= Test.k;   i= Foo.k;   )   )   What is the result? ()A Compilation succeeds.B An error at line 2 causes compilation to fail.C An error at line 9 causes compilation to fail.D An error at line 10 causes compilation to fail.E An error at line 11 causes compilation to fail.

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

多选题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 */ }

多选题Which statements concerning the relationships between the following classes are true?()   class Foo {  int num;   Baz comp = new Baz();   }   class Bar {  boolean flag;   }   class Baz extends Foo {   Bar thing = new Bar();   double limit;   }AA Bar is a Baz.BA Foo has a Bar.CA Baz is a Foo.DA Foo is a Baz.EA Baz has a Bar.

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

单选题1. interface foo {  2. int k = 0;  3. } 4.    5. public class test implements Foo (  6. public static void main(String args[]) (  7. int i;  8. Test test = new test ();  9. i= test.k;  10.i= Test.k;  11.i= Foo.k;  12.)  13.)  14.        What is the result?()A Compilation succeeds.B An error at line 2 causes compilation to fail.C An error at line 9 causes compilation to fail.D An error at line 10 causes compilation to fail.E An error at line 11 causes compilation to fail.

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

多选题A developer is creating a class Book, that needs to access class Paper. The Paper class is deployed in a JAR named myLib.jar. Which three, taken independently, will allow the developer to use the Paper class while compiling the Book class?()AThe JAR file is located at $JAVA_HOME/jre/classes/myLib.jar.BThe JAR file is located at $JAVA_HOME/jre/lib/ext/myLib.jar..CThe JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar/Paper.class.DThe JAR file is located at /foo/myLib.jar and a classpath environment variable is set that includes /foo/myLib.jar.EThe JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -cp /foo/myLib.jar/Paper Book.java.FThe JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -d /foo/myLib.jar Book.javaGThe JAR file is located at /foo/myLib.jar and the Book class is compiled using javac -classpath /foo/myLib.jar Book.java

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

单选题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. 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().

单选题1.public class Test {  2.public static void main (String args[]) {  3.class Foo {  4.public int i = 3;  5.}  6.Object o = (Object) new Foo();  7.Foo foo = (Foo)o;  8.System.out.printIn(foo. i); 9. }  10.}   What is the result?()A Compilation will fail.B Compilation will succeed and the program will print “3”C Compilation will succeed but the program will throw a ClassCastException at line 6.D Compilation will succeed but the program will throw a ClassCastException at line 7.

填空题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?()

多选题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; }

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