单选题Given: Which code, inserted at line 16, will cause a java.lang.ClassCastException?()AAlpha a = x;BFoo f = (Delta)x;CFoo f = (Alpha)x;DBeta 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;


相似考题
参考答案和解析
正确答案: B
解析: 暂无解析
更多“单选题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;”相关问题
  • 第1题:

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


    参考答案:B, C, E

  • 第2题:

    如果类Alpha继承了类Beta,则类Alpha称为派生类,类Beta称为【 】类。


    正确答案:基
    基 解析:在C++语言中,可以从一个类派生出另一个类。派生其他类的类称为基类(或父类),被派生的类称为派生类(或子类)。一个派生类可以从一个基类派生,也可以从多个基类派生。从一个基类派生的继承称为单继承,从多个基类派生的继承称为多继承。

  • 第3题:

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

    正确答案:B,C

  • 第4题:

    现有如下包结构:  com |-- x | |-- Alpha.class | | | |-- y | |-- Beta.class | |-- Gamma.class  和类:  class Test { Alpha a; Beta b; Gamma c; }  哪三个必须加入到类 Test 中,以使其通过编译?()

    • A、package y;
    • B、package com;
    • C、import com.x.*;
    • D、import com.x.y.*

    正确答案:B,C,D

  • 第5题:

    Given the JSP code: <% request.setAttribute("foo", "bar"); %>and the Classic tag handler code: 5. public int doStartTag() throws JspException { 6. // insert code here 7. // return int 8. } Assume there are no other "foo" attributes in the web application. Which invocation on the pageContextobject,inserted at line 6,assigns "bar" to the variable x?()

    • A、String x = (String) pageContext.getAttribute("foo")
    • B、String x = (String) pageContext.getRequestScope("foo")
    • C、It is NOT possible to access the pageContext object from within doStartTag
    • D、String x = (String) pageContext.getRequest().getAttribute("foo")
    • E、String x = (String) pageContext.getAttribute("foo", PageContext.ANY_SCOPE)

    正确答案:D

  • 第6题:

    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

  • 第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;


    正确答案: C
    解析: 暂无解析

  • 第8题:

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


    正确答案: C
    解析: 暂无解析

  • 第9题:

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


    正确答案: B
    解析: 暂无解析

  • 第10题:

    多选题
    现有如下包结构:  com |-- x | |-- Alpha.class | | | |-- y | |-- Beta.class | |-- Gamma.class  和类:  class Test { Alpha a; Beta b; Gamma c; }  哪三个必须加入到类 Test 中,以使其通过编译?()
    A

    package y;

    B

    package com;

    C

    import com.x.*;

    D

    import com.x.y.*


    正确答案: C,B
    解析: 暂无解析

  • 第11题:

    单选题
    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
    解析: 暂无解析

  • 第12题:

    单选题
    Given the JSP code: and the Classic tag handler code: 5. public int doStartTag() throws JspException { 6. // insert code here 7. // return int 8. } Assume there are no other "foo" attributes in the web application. Which invocation on the pageContextobject,inserted at line 6,assigns "bar" to the variable x?()
    A

    String x = (String) pageContext.getAttribute(foo)

    B

    String x = (String) pageContext.getRequestScope(foo)

    C

    It is NOT possible to access the pageContext object from within doStartTag

    D

    String x = (String) pageContext.getRequest().getAttribute(foo)

    E

    String x = (String) pageContext.getAttribute(foo, PageContext.ANY_SCOPE)


    正确答案: B
    解析: 暂无解析

  • 第13题:

    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;


    参考答案:B

  • 第14题:

    现有如F包结构:      com     |一一X      |    |一一Alpha.class     |    |      |    |一一y      I         |一一Beta.class     |      |l-- Gamma.class    和类:      class Test  {  Alpha a;  Beta b; Gamma c;  }  哪三个必须加入到类Test中,以使其通过编译?() 

    • A、 package y;
    • B、 package com;
    • C、 import com.x.y.*;
    • D、 import com.x.*;

    正确答案:B,C,D

  • 第15题:

    现有包结构:  com |-- x | |-- Alpha.class | | | |-- y | |-- Beta.class | |-- Gamma.class  和类:  //insert code here  import com.*;  import com.x.y.*;  class Test { Alpha a; Beta b; Gamma c; }  哪两行分别插入后可允许代码编译?() 

    • A、package com.;
    • B、import com.x;
    • C、package com.x;
    • D、import com.x.Alpha;

    正确答案:C,D

  • 第16题:

    表达式re.split(’/.+’,’alpha.beta...gamma..delta’)的值为()。


    正确答案:['alpha', 'beta', 'gamma', 'delta']

  • 第17题:

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

    正确答案:D

  • 第18题:

    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、 Tested
    • B、 Compilation fails.
    • C、 The code runs with no output.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第19题:

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

     Tested

    B

     Compilation fails.

    C

     The code runs with no output.

    D

     An exception is thrown at runtime.


    正确答案: C
    解析: 暂无解析

  • 第20题:

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


    正确答案: D,B
    解析: 暂无解析

  • 第21题:

    多选题
    现有如F包结构:      com     |一一X      |    |一一Alpha.class     |    |      |    |一一y      I         |一一Beta.class     |      |l-- Gamma.class    和类:      class Test  {  Alpha a;  Beta b; Gamma c;  }  哪三个必须加入到类Test中,以使其通过编译?()
    A

    package y;

    B

    package com;

    C

    import com.x.y.*;

    D

    import com.x.*;


    正确答案: B,C
    解析: 暂无解析

  • 第22题:

    多选题
    现有包结构:  com |-- x | |-- Alpha.class | | | |-- y | |-- Beta.class | |-- Gamma.class  和类:  //insert code here  import com.*;  import com.x.y.*;  class Test { Alpha a; Beta b; Gamma c; }  哪两行分别插入后可允许代码编译?()
    A

    package com.;

    B

    import com.x;

    C

    package com.x;

    D

    import com.x.Alpha;


    正确答案: C,D
    解析: 暂无解析

  • 第23题:

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


    正确答案: B,C
    解析: 暂无解析