单选题Given:   11. public static void main(String[] args) {   12. Object obj = new int[] { 1, 2, 3 };   13. int[] someArray = (int[])obj;   14. for (int i : someArray) System.out.print(i + " ");   15. }   What is the result? ()A  Compilation fails because of

题目
单选题
Given:   11. public static void main(String[] args) {   12. Object obj = new int[] { 1, 2, 3 };   13. int[] someArray = (int[])obj;   14. for (int i : someArray) System.out.print(i + " ");   15. }   What is the result? ()
A

 Compilation fails because of an error in line 13.

B

 A ClassCastException is thrown at runtime.

C

 1 2 3

D

 Compilation fails because of an error in line 14.

E

 Compilation fails because of an error in line 12.

参考答案和解析
正确答案: A
解析: 暂无解析
如果没有搜索结果或未解决您的问题,请直接 联系老师 获取答案。
相似问题和答案

第1题:

Given:11.publicstaticvoidmain(String[]args){12.Objectobj=newint[]{1,2,3};13.int[]someArray=(int[])obj;14.for(inti:someArray)System.out.print(i+"");15.}Whatistheresult?()

A.Compilationfailsbecauseofanerrorinline13.

B.AClassCastExceptionisthrownatruntime.

C.123

D.Compilationfailsbecauseofanerrorinline14.

E.Compilationfailsbecauseofanerrorinline12.


参考答案:C

第2题:

1. class A {  2. public int getNumber(int a) {  3.     return a + 1;  4. }  5. }  6.    7. class B extends A {  8. public int getNumber (int a) {  9. return a + 2  10. }  11.    12. public static void main (String args[])  {  13. A a = new B();  14. System.out.printIn(a.getNumber(0));  15.    } 16. }     What is the result?()  

  • A、 Compilation succeeds and 1 is printed.
  • B、 Compilation succeeds and 2 is printed.
  • C、 An error at line 8 causes compilation to fail.
  • D、 An error at line 13 causes compilation to fail.
  • E、 An error at line 14 causes compilation to fail.

正确答案:B

第3题:

public static void main(String[]args){12.Object obj=new int[]{1,2,3};13.int[] someArray=(int[])obj;14.for(inti:someArray)System.out.print(i+"")15.}What is the result?()

A.123

B.Compilation fails because of an error in line 12.

C.Compilation fails because of an error in line 13.

D.Compilation fails because of an error in line 14.

E.A ClassCastException is thrown at runtime.


参考答案:A

第4题:

11. public static void main(String[] args) {  12. Object obj = new Object() {  13. public int hashCode() {  14. returns 42; 15. }  16. };  17. System.out.println(obj.hashCode());  18. }    What is the result? () 

  • A、 42
  • B、 An exception is thrown at runtime.
  • C、 Compilation fails because of an error on line 12.
  • D、 Compilation fails because of an error on line 16.
  • E、 Compilation fails because of an error on line 17.

正确答案:A

第5题:

11. public static void main(String[] args) {  12. Integer i = uew Integer(1) + new Integer(2);  13. switch(i) {  14. case 3: System.out.println(”three”); break;  15. default: System.out.println(”other”); break;  16. }  17. }  What is the result?() 

  • A、 three
  • B、 other
  • C、 An exception is thrown at runtime.
  • D、 Compilation fails because of an error on line 12.
  • E、 Compilation fails because of an error on line 13.
  • F、 Compilation fails because of an error on line 15.

正确答案:A

第6题:

下列程序的执行结果是 ( ) public class ex68{ public static void main(String[]args){ ex68 obj=new ex68(); int s=0; for(int i=1;i<=4;i++){ s+=obj.method(i); } System.out.println(s); } public int method(int n){ if(n==1) return 1; else return n*method(n-1); } }

A.3

B.9

C.33

D.153


正确答案:C
解析:该题考查的是递归调用。在Java中允许方法的递归调用,即允许方法调用自身。当算阶乘的时候最多的是用到递归调用,本题算的是从1到4的递归的和。

第7题:

11. public static void main(String[] args) {  12. Object obj =new int[] { 1,2,3 };  13. int[] someArray = (int[])obj;  14. for (int i: someArray) System.out.print(i +“ “)  15. }  What is the result? ()

  • A、 1 2 3
  • B、 Compilation fails because of an error in line 12.
  • C、 Compilation fails because of an error in line 13.
  • D、 Compilation fails because of an error in line 14.
  • E、 A ClassCastException is thrown at runtime.

正确答案:A

第8题:

publicstaticvoidmain(String[]args){12.Objectobj=newint[]{1,2,3};13.int[]someArray=(int[])obj;14.for(inti:someArray)System.out.print(i+)15.}Whatistheresult?()

A.123

B.Compilationfailsbecauseofanerrorinline12.

C.Compilationfailsbecauseofanerrorinline13.

D.Compilationfailsbecauseofanerrorinline14.

E.AClassCastExceptionisthrownatruntime.


参考答案:A

第9题:

class Super {  public int i = 0;  public Super(String text) {  i = 1; }  }  public class Sub extends Super {  public Sub(String text) {  i = 2;  }   public static void main(String args[]) {  Sub sub = new Sub(“Hello”);  System.out.println(sub.i);  }  }  What is the result?()  

  • A、 0
  • B、 1
  • C、 2
  • D、 Compilation fails.

正确答案:C

第10题:

11. class Converter {  12. public static void main(String[] args) {  13. Integer i = args[0];  14. int j = 12;  15. System.out.println(”It is “ + (j==i) + “that j==i.”);  16. }  17. }  What is the result when the programmer attempts to compile the code and run it with the command java Converter 12?() 

  • A、 It is true that j==i.
  • B、 It is false that j==i.
  • C、 An exception is thrown at runtime.
  • D、 Compilation fails because of an error in line 13.

正确答案:D

更多相关问题