单选题public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()A0BnullCCompilation fails.DA NullPointerException is thrown at runtime.EAn ArrayIndexOutOfBoundsException is 

题目
单选题
public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()
A

 0

B

 null

C

 Compilation fails.

D

 A NullPointerException is thrown at runtime.

E

 An ArrayIndexOutOfBoundsException is thrown at runtime.


相似考题
参考答案和解析
正确答案: D
解析: 暂无解析
更多“单选题public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()A  0B  nullC  Compilation fails.D  A NullPointerException is thrown at runtime.E  An ArrayIndexOutOfBoundsExc”相关问题
  • 第1题:

    public class Test {  public static void main(String[] args) {  String str = NULL;  System.out.println(str);  }  }   What is the result?()  

    • A、 NULL
    • B、 Compilation fails.
    • C、 The code runs with no output.
    • D、 An exception is thrown at runtime.

    正确答案:B

  • 第2题:

    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

  • 第3题:

    public class Yikes {  public static void go(Long n) {System.out.println(”Long “);}  public static void go(Short n) {System.out.println(”Short “);}  public static void go(int n) {System.out.println(”int “);}  public static void main(String [] args) {  short y= 6;  long z= 7;  go(y);  go(z);  }  }  What is the result?() 

    • A、 int Long
    • B、 Short Long
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:A

  • 第4题:

    public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()   

    • A、 0
    • B、 null
    • C、 Compilation fails.
    • D、 A NullPointerException is thrown at runtime.
    • E、 An ArrayIndexOutOfBoundsException is thrown at runtime.

    正确答案:D

  • 第5题:

    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()  

    • A、 finished
    • B、 Compilation fails.
    • C、 An AssertionError is thrown.
    • D、 An AssertionError is thrown and finished is output.

    正确答案:A

  • 第6题:

    单选题
    public class Test {  private static float[] f = new float[2];  public static void main(String args[]) {  System.out.println(“f[0] = “ + f[0]);  }  }   What is the result?()
    A

     f[0] = 0

    B

     f[0] = 0.0

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第7题:

    单选题
    public class Test {  public static void main(String [] args) {  System.out.println(args.length > 4 &&  args[4].equals(“-d”));  }  }   If the program is invoked using the command line: java Test One Two Three –d   What is the result?()
    A

     true

    B

     false

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


    正确答案: B
    解析: The correct answer to this question is D. The args[4] generates a runtime exception error because there are only 4 strings and the expression args[4] prints the 5th String but like it was said earlier, there are only 4 strings. 

  • 第8题:

    单选题
    public class Test {  public static void main( String[] args) {  String foo = args[1];  String bar = args[2];  String baz = args[3];  System.out.println(“baz = “ + baz); }  }   And the command line invocation: java Test red green blue   What is the result?()
    A

     baz =

    B

     baz = null

    C

     baz = blue

    D

     Compilation fails.

    E

     An exception is thrown at runtime.


    正确答案: C
    解析: A java.lang.ArrayIndexOutOfBoundsException is thrown because of line 3, should be args[0].

  • 第9题:

    单选题
    class TestA {  public void start() { System.out.println(”TestA”); }  }  public class TestB extends TestA {  public void start() { System.out.println(”TestB”); } public static void main(String[] args) {  ((TestA)new TestB()).start();  }  }  What is the result?()
    A

     TestA

    B

     TestB

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第10题:

    单选题
    public class Yikes {  public static void go(Long n) {System.out.println(”Long “);}  public static void go(Short n) {System.out.println(”Short “);}  public static void go(int n) {System.out.println(”int “);}  public static void main(String [] args) {  short y= 6;  long z= 7;  go(y);  go(z);  }  }  What is the result?()
    A

     int Long

    B

     Short Long

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第11题:

    单选题
    public class Test {  public static void main(String[] args) {  String str = NULL;  System.out.println(str);  }  }   What is the result?()
    A

     NULL

    B

     Compilation fails.

    C

     The code runs with no output.

    D

     An exception is thrown at runtime.


    正确答案: C
    解析: NULL should be "null".

  • 第12题:

    单选题
    public class Wow {  public static void go(short n) {System.out.println(”short”); }  public static void go(Short n) {System.out.println(”SHORT”);}  public static void go(Long n) {System.out.println(” LONG”); }  public static void main(String [] args) {  Short y= 6;  int z=7;  go(y);  go(z);  }  }  What is the result?()
    A

     short LONG

    B

     SHORT LONG

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第13题:

    public class Test {  public static void main( String[] args) {  String foo = args[1];  String bar = args[2];  String baz = args[3];  System.out.println(“baz = “ + baz); }  }   And the command line invocation: java Test red green blue   What is the result?()  

    • A、 baz =
    • B、 baz = null
    • C、 baz = blue
    • D、 Compilation fails.
    • E、 An exception is thrown at runtime.

    正确答案:E

  • 第14题:

    public static void main(String[] args) {  try {  args=null;  args[0] = “test”;  System.out.println(args[0]);  } catch (Exception ex) {  System.out.println(”Exception”);  } catch (NullPointerException npe) {  System.out.println(”NullPointerException”);  }  }  What is the result?() 

    • A、 test
    • B、 Exception
    • C、 Compilation fails.
    • D、 NullPointerException

    正确答案:C

  • 第15题:

    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0) ? “assertion failed” : “assertion passed”;  System.out.println(“Finished”);  }  }  What is the result?()  

    • A、 finished
    • B、 Compilation fails.
    • C、 An AssertionError is thrown and finished is output.
    • D、 An AssertionError is thrown with the message “assertion failed”.
    • E、 An AssertionError is thrown with the message “assertion passed”.

    正确答案:B

  • 第16题:

    public class Wow {  public static void go(short n) {System.out.println(”short”); }  public static void go(Short n) {System.out.println(”SHORT”);}  public static void go(Long n) {System.out.println(” LONG”); }  public static void main(String [] args) {  Short y= 6;  int z=7;  go(y);  go(z);  }  }  What is the result?() 

    • A、 short LONG
    • B、 SHORT LONG
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:C

  • 第17题:

    public class Test {  public static void main(String [] args) {  System.out.println(args.length > 4 &&  args[4].equals(“-d”));  }  }   If the program is invoked using the command line: java Test One Two Three –d   What is the result?()  

    • A、 true
    • B、 false
    • C、 Compilation fails.
    • D、 An exception is thrown at runtime.

    正确答案:D

  • 第18题:

    单选题
    public class Test {  private static int[] x;  public static void main(String[] args) {  System.out.println(x[0]);  }  }   What is the result?()
    A

     0

    B

     null

    C

     Compilation fails.

    D

     A NullPointerException is thrown at runtime.

    E

     An ArrayIndexOutOfBoundsException is thrown at runtime.


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

  • 第19题:

    单选题
    public static void main(String[] args) {  try {  args=null;  args[0] = “test”;  System.out.println(args[0]);  } catch (Exception ex) {  System.out.println(”Exception”);  } catch (NullPointerException npe) {  System.out.println(”NullPointerException”);  }  }  What is the result?()
    A

     test

    B

     Exception

    C

     Compilation fails.

    D

     NullPointerException


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

  • 第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题:

    单选题
    package test1;  public class Test1 {  static int x = 42;  }  package test2;  public class Test2 extends test1.Test1 {  public static void main(String[] args) { System.out.println(“x = “ + x);  }  }  What is the result?()
    A

     x = 0

    B

     x = 42

    C

     Compilation fails because of an error in line 2 of class Test2.

    D

     Compilation fails because of an error in line 3 of class Test1.

    E

     Compilation fails because of an error in line 4 of class Test2.


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

  • 第22题:

    单选题
    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0) ? “assertion failed” : “assertion passed”;  System.out.println(“Finished”);  }  }  What is the result?()
    A

     finished

    B

     Compilation fails.

    C

     An AssertionError is thrown and finished is output.

    D

     An AssertionError is thrown with the message “assertion failed”.

    E

     An AssertionError is thrown with the message “assertion passed”.


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

  • 第23题:

    单选题
    public class Test {  public static void add3 (Integer i) {  int val = i.intValue();  val += 3;  i = new Integer(val); }  public static void main(String args[]) {  Integer i = new Integer(0);  add3(i);  System.out.println(i.intValue());  }  }   What is the result? ()
    A

     0

    B

     3

    C

     Compilation fails.

    D

     An exception is thrown at runtime.


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

  • 第24题:

    单选题
    public class Test {  public static void main(String[] args) {  int x = 0;  assert (x > 0): “assertion failed”;  System.out.println(“finished”);  }  }  What is the result?()
    A

     finished

    B

     Compilation fails.

    C

     An AssertionError is thrown.

    D

     An AssertionError is thrown and finished is output.


    正确答案: D
    解析: This question is a bit tricky because it lacks the following information: It should include a statement that says whether or not assertions are enabled. If they are indeed enabled, the 
    correction answer is C. but if they are not, the correct answer is A. Assertions are not enabled by default so if the question is not changed, the most logical answer is A.