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

题目
单选题
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
解析: 暂无解析
更多“Which code, inserted at line 16, will cause a java.lang.Clas”相关问题
  • 第1题:

    多选题
    Which two are true about has-a and is-a relationships?()
    A

    Inheritance represents an is-a relationship.

    B

    Inheritance represents a has-a relationship.

    C

    Interfaces must be used when creating a has-a relationship.

    D

    Instance variables can be used when creating a has-a relationship.


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

  • 第2题:

    单选题
    public static void main(String[] args) {  for (int i=0;i6) break;  }  System.out.println(i);  }  What is the result?()
    A

     6

    B

     7

    C

     10

    D

     11

    E

     Compilation fails.

    F

     An exception is thrown at runtime.


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

  • 第3题:

    单选题
    public class Foo implements Runnable (  public void run (Thread t) {   system.out.printIn(“Running.”);   }   public static void main (String args) {   new thread (new Foo()).start();   }   )   What is the result?()
    A

     An exception is thrown.

    B

     The program exists without printing anything.

    C

     An error at line 1 causes compilation to fail.

    D

     An error at line 6 causes the compilation to fail.

    E

     “Running” is printed and the program exits.


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

  • 第4题:

    单选题
    11. static classA {  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

     B

    B

     The code runs with no output.

    C

     An exception is thrown at runtime.

    D

     Compilation fails because of an error in line 15.

    E

     Compilation fails because of an error in line 18.

    F

     Compilation fails because of an error in line 19.


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

  • 第5题:

    多选题
    Which statements describe guaranteed behavior of the garbage collection and finalization mechanisms?()
    A

    Objects are deleted when they can no longer be accessed through any reference.

    B

    The finalize() method will eventually be called on every object.

    C

    The finalize() method will never be called more than once on an object.

    D

    An object will not be garbage collected as long as it is possible for an active part of the program to      access it through a reference.

    E

    The garbage collector will use a mark and sweep algorithm.


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

  • 第6题:

    单选题
    A class games.cards.Poker is correctly defined in the jar file Poker.jar.  A user wants to execute the main method of Poker on a UNIX system using the command:  java games.cards.Poker  What allows the user to do this?()
    A

     put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java

    B

     put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/*.jar

    C

     Put Poker.jar in directory /stuff/java, and set the CLASSPATH to include /stuff/java/Poker.jar

    D

     put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java

    E

     put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuffijava/*.jar

    F

     put Poker.jar in directory /stuff/java/games/cards, and set the CLASSPATH to include /stuff/java/Poker.jar


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

  • 第7题:

    单选题
    11. public void testIfA() {  12. if(testIfB(”True”)) {  13. System.out.println(”True”);  14. } else {  15. System.out.println(”Not true”);  16. }  17. }  18. public Boolean testIfB(String str) {  19. return Boolean.valueOf(str);  20. }  What is the result when method testIfA is invoked?()
    A

     True

    B

     Not true

    C

     An exception is thrown at runtime.

    D

     Compilation fails because of an error at line 12.

    E

     Compilation fails because of an error at line 19.


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

  • 第8题:

    单选题
    Which code determines the int value foo closest to a double value bar?()
    A

     Int foo = (int) Math.max(bar);

    B

     Int foo = (int) Math.min(bar);

    C

     Int foo = (int) Math.abs(bar);

    D

     Int foo = (int) Math.ceil(bar);

    E

     Int foo = (int) Math.floor(bar);

    F

     Int foo = (int) Math.round(bar);


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

  • 第9题:

    单选题
    Given the following code fragment:      1) String str = null;  2) if ((str != null) && (str.length() > 10)) {     3) System.out.println("more than 10");     4) }  5) else if ((str != null) & (str.length() < 5)) {     6) System.out.println("less than 5");     7) }  8) else { System.out.println("end"); }   Which line will cause error?()
    A

     line 1

    B

     line 2

    C

     line 5

    D

     line 8


    正确答案: B
    解析: 此题需要将代码仔细看清楚,查询没有逻辑错误,if …else的使用没有问题,也没有拼写错误,错误在于第5行的“与”操作符的使用,逻辑操作符(logical operator)的“与” 应该是&&,而&是位逻辑操作符(bitwise logical operator)的“与”,使用的对象不一样,逻辑操作符的“与”的左右操作数都应该是布尔型(logical boolan)的值,而位逻辑操作符的左右操作数都是整型(integral)值。

  • 第10题:

    单选题
    Given a class Repetition:  1. package utils;  2.  3. public class Repetition {  4. public static String twice(String s) { return s + s; }  5. }  and given another class Demo:  1. // insert code here 2.  3. public class Demo {  4. public static void main(String[] args) {  5. System.out.println(twice(”pizza”));  6. }  7. }  Which code should be inserted at line 1 of Demo.java to compile and run Demo to print“pizzapizza”?()
    A

     import utils.*;

    B

     static import utils.*;

    C

     import utils.Repetition.*;

    D

     static import utils.Repetition. *;

    E

     import utils.Repetition.twice();

    F

     import static utils.Repetition.twice;

    G

     static import utils.Repetition.twice;


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

  • 第11题:

    单选题
    What will be written to the standard output when the following program is run?()  public class Qd803 {   public static void main(String args[]) {   String word = "restructure";   System.out.println(word.substring(2, 3));   }   }
    A

    est

    B

    es

    C

    str

    D

    st

    E

    s


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

  • 第12题:

    单选题
    ClassOne.java: 1. package com.abe.pkg1; 2. public class ClassOne { 3. private char var = ‘a’; 4. char getVar() { return var; } 5. } ClassTest.java: 1. package com.abe.pkg2; 2. import com.abc.pkg1.ClassOne; 3. public class ClassTest extends ClassOne { 4. public static void main(String[] args) { 5. char a = new ClassOne().getVar();6. char b = new ClassTest().getVar(); 7. } 8. } What is the result?()
    A

     Compilation fails.

    B

     Compilation succeeds and no exceptions are thrown.

    C

     An exception is thrown at line 5 in ClassTest.java.

    D

     An exception is thrown at line 6 in ClassTest.java.


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

  • 第13题:

    单选题
    Which can be used to decode charS for output?()
    A

     Java.io.InputStream.

    B

     Java.io.EncodedReader.

    C

     Java.io.InputStreamReader.

    D

     Java.io.InputStreamWriter.

    E

     Java.io.BufferedInputStream.


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

  • 第14题:

    填空题
    What is the name of the method that threads can use to pause their execution until signalled to continue by another thread? () Fill in the name of the method (do not include a parameter list).

    正确答案: "wait"
    解析: 暂无解析

  • 第15题:

    多选题
    public class Threads2 implements Runnable {  public void nun() {  System.out.println(”run.”);  throw new RuntimeException(”Problem”);  }  public static void main(String[] args) {  Thread t = new Thread(new Threads2());  t.start();  System.out.println(”End of method.”);  }  }  Which two can be results?()
    A

    java.lang.RuntimeException: Problem

    B

    run.    java.lang.RuntimeException: Problem

    C

    End of method.    java.lang.RuntimeException: Problem

    D

    End of method.      run.      java.lang.RuntimeException: Problem

    E

    run.    java.lang.RuntimeException: Problem     End of method.


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

  • 第16题:

    多选题
    public class X {  public X aMethod() { return this;}  }  public class Y extends X {  }  Which two methods can be added to the definition of class Y?()
    A

    public void aMethod() {}

    B

    private void aMethod() {}

    C

    public void aMethod(String s) {}

    D

    private Y aMethod() { return null; }

    E

    public X aMethod() { return new Y(); }


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

  • 第17题:

    单选题
    class ClassA {  public int numberOfinstances;  protected ClassA(int numberOfinstances) {  this.numberOflnstances = numberOfinstances;  }  }  public class ExtendedA extends ClassA {  private ExtendedA(int numberOfinstances) {  super(numberOflnstances);  }  public static void main(String[] args) {  ExtendedA ext = new ExtendedA(420);  System.out.print(ext.numberOflnstances);  }  }  Which is true?()
    A

     420 is the output.

    B

     An exception is thrown at runtime.

    C

     All constructors must be declared public.

    D

     Constructors CANNOT use the private modifier.

    E

     Constructors CANNOT use the protected modifier.


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

  • 第18题:

    单选题
    1. abstract class AbstractIt {  2. abstract float getFloat();  3. }  4. public class AbstractTest extends AbstractIt {  5. private float f1 = 1.0f;  6. private float getFloat() { return f1; }  7. }  What is the result?()
    A

     Compilation succeeds.

    B

     An exception is thrown.

    C

     Compilation fails because of an error at line 2.

    D

     Compilation fails because of an error at line 6.


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

  • 第19题:

    多选题
    Which statements are true concerning the default layout manager for containers in the java.awt package?()
    A

    Objects instantiated from Panel do not have a default layout manager.

    B

    Objects instantiated from Panel have FlowLayout as default layout manager.

    C

    Objects instantiated from Applet have BorderLayout as default layout manager.

    D

    Objects instantiated from Dialog have BorderLayout as default layout manager.

    E

    Objects instantiated from Window have the same default layout manager as instances of Applet.


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

  • 第20题:

    多选题
    public class Parent {  public int addValue( int a, int b) {     int s;     s = a+b;     return s;     }     }  class Child extends Parent {  }  Which methods can be added into class Child?()
    A

    int addValue( int a, int b ){// do something...}

    B

    public void addValue (){// do something...}

    C

    public int addValue( int a ){// do something...}

    D

    public int addValue( int a, int b )throws MyException {//do something...}


    正确答案: C,A
    解析: 此题涉及方法重载(overload),方法重写(override)以及类派生时方法重写的规则。方法重载的规则是:
    一、参数列表必须不同,个数的不同完全可以,如果个数相同则参数类型的不同不能引起歧意,例如int 和long,float和double就不能作为唯一的类型不同;
    二、返回值可以不同,但是不能是重载时唯一的不同点(这点和c++中不同,c++中返回类型必须一致)。
    方法重写发生在类继承时,子类可以重写一个父类中已有的方法,必须在返回类型和参数列表一样时才能说是重写,否则就是重载,java中方法重写的一个重要而且容易被忽略的规则是重写的方法的访问权限不能比被重写的方法的访问权限低!重写的另一个规则是重写的方法不能比被重写的方法抛弃(throws)更多种类的异常,其抛弃的异常只能少,或者是其子类,不能以抛弃异常的个数来判断种类,而应该是异常类层次结果上的种类。此题中答案a的错误就是重写的访问权限比被重写的方法的低,而b,c都属于重载,d的错误在于比被重写的方法抛弃了更多种类的异常。

  • 第21题:

    单选题
    1. class A implements Runnable (  2. int i;  3. public void run ( ) (  4. try (  5. thread.sleep(5000);  6. i= 10;  7. ) catch(InterruptedException e) {}  8. )  9. )  10.    11. public class Test {  12. public static void  main (string args[]) ( 13. try (  14. A a = new A ( );  15. Thread t = new Thread (a);  16. t.start( );  17.    18. int j= a.i;  19.    20. ) catch (Exception e) {}  21. )  22. }   Which statement al line 17 will ensure that j=10 at line 19?()
    A

     a.wait();

    B

     t.wait();

    C

     t.join();

    D

     t.yield();

    E

     t.notify();

    F

     a.notify();

    G

     t.interrupt();


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

  • 第22题:

    多选题
    public class Parent {     int change() {…}     }  class Child extends Parent {     }  Which methods can be added into class Child?()
    A

    public int change(){}

    B

    int chang(int i){}

    C

    private int change(){}

    D

    abstract int chang(){}


    正确答案: A,B
    解析: 这个题目的问题在第35题中有详尽的叙述。需要注意的是答案D的内容,子类可以重写父类的方法并将之声明为抽象方法,但是这引发的问题是类必须声明为抽象类,否则编译不能通过,而且抽象方法不能有方法体,也就是方法声明后面不能带上那两个大括号({}),这些D都不能满足。

  • 第23题:

    单选题
    Which statement is true?()
    A

     If only one thread is blocked in the wait method of an object, and another thread executes the modify on that same object, then the first thread immediately resumes execution.

    B

     If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, it is still possible that the first thread might never resume execution.

    C

     If a thread is blocked in the wait method of an object, and another thread executes the notify method on the same object, then the first thread definitely resumes execution as a direct and sole  consequence of the notify call.

    D

     If two threads are blocked in the wait method of one object, and another thread executes the notify method on the same object, then the first thread that executed the wait call first definitely resumes execution as a direct and sole consequence of the notify call.


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

  • 第24题:

    单选题
    interface Data { public void load(); }  abstract class Info { public abstract void load(); }  Which class correctly uses the Data interface and Info class?()
    A

     public class Employee extends Info implements Data { public void load() { /*do something*/ } }

    B

     public class Employee implements Info extends Data { public void load() { /*do something*/ } }

    C

     public class Employee extends Info implements Data { public void load() { /*do something */ } public void Info.load() { /*do something*/ } }

    D

     public class Employee implements Info extends Data { public void Data.load() { /*dsomething */ } public void load() { /*do something */ } }

    E

     public class Employee implements Info extends Data { public void load() { /*do something */ } public void Info.load(){ /*do something*/ } }

    F

     public class Employee extends Info implements Data{ public void Data.load() { /*do something*/ } public void Info.load() { /*do something*/ } }


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