单选题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? ()ACompilation fails because of a

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


相似考题
更多“单选题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”相关问题
  • 第1题:

    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

  • 第2题:

    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

  • 第3题:

    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

  • 第4题:

    package foo;  import java.util.Vector; private class MyVector extends Vector {  int i = 1;  public MyVector() {  i = 2; } }  public class MyNewVector extends MyVector {  public MyNewVector() {  i = 4;  }  public static void main(String args[]) {  MyVector v = new MyNewVector();  }  }  What is the result?()

    • A、 Compilation succeeds.
    • B、 Compilation fails because of an error at line 5.
    • C、 Compilation fails because of an error at line 6.
    • D、 Compilation fails because of an error at line 14.
    • E、 Compilation fails because of an error at line 17.

    正确答案:B

  • 第5题:

    public class test(    public int aMethod()[   static int i=0;   i++;   return I;   )    public static void main (String args){   test test = new test();    test.aMethod();   int j = test.aMethod();   System.out.printIn(j);   ]  }   What is the result?()

    • A、 Compilation will fail.
    • B、 Compilation will succeed and the program will print “0”
    • C、 Compilation will succeed and the program will print “1”
    • D、 Compilation will succeed and the program will print “2”

    正确答案:D

  • 第6题:

    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()  

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

    正确答案:D

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


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

  • 第8题:

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


    正确答案: B
    解析: This code is perfectly legal and the answer is C. 

  • 第9题:

    单选题
    package foo;  import java.util.Vector; private class MyVector extends Vector {  int i = 1;  public MyVector() {  i = 2; } }  public class MyNewVector extends MyVector {  public MyNewVector() {  i = 4;  }  public static void main(String args[]) {  MyVector v = new MyNewVector();  }  }  What is the result?()
    A

     Compilation succeeds.

    B

     Compilation fails because of an error at line 5.

    C

     Compilation fails because of an error at line 6.

    D

     Compilation fails because of an error at line 14.

    E

     Compilation fails because of an error at line 17.


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

  • 第10题:

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


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

  • 第11题:

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

  • 第12题:

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


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

  • 第13题:

    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

  • 第14题:

    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

  • 第15题:

    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

  • 第16题:

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

  • 第17题:

    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 = 3
    • B、 Compilation fails.
    • C、 A ClassCastException is thrown at line 6.
    • D、 A ClassCastException is thrown at line 7.

    正确答案:A

  • 第18题:

    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、 B
    • D、 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.

    正确答案:A

  • 第19题:

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


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

  • 第20题:

    单选题
    public class Test {  public int aMethod() {  static int i = 0;  i++;  return i;  }  public static void main (String args[]) {  Test test = new Test();  test.aMethod();  int j = test.aMethod();  System.out.println(j);  }  }  What is the result?()
    A

     0

    B

     1

    C

     2

    D

     Compilation fails.


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

  • 第21题:

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

    B

     Compilation fails.

    C

     A ClassCastException is thrown at line 6.

    D

     A ClassCastException is thrown at line 7.


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

  • 第22题:

    单选题
    public class test(  public int aMethod()[  static int i=0;  i++;  return I;  )  public static void main (String args[]){  test test = new test();  test.aMethod();  int j = test.aMethod();  System.out.printIn(j);  ]  }        What is the result?()
    A

     Compilation will fail.

    B

     Compilation will succeed and the program will print “0”

    C

     Compilation will succeed and the program will print “1”

    D

     Compilation will succeed and the program will print “2”


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

  • 第23题:

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


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