Array Creation and Access

AP Computer Science A· difficulty 4/5

String[] s = new String[3];
System.out.println(s[0].length());

What happens?

  • A

    ArrayIndexOutOfBoundsException is thrown

  • B

    Prints null

  • C

    Prints 0

  • D

    NullPointerException is thrown

    check_circle

Explanation

s[0] is null. Calling .length() on null throws a NullPointerException.

Want 10 more like this — adaptive to your weak spots?

Related questions