Java Array Null Pointer Exception
What is the result of executing the following code segment?
public class NullObjectTest {
public static void main(String[] args) {
String[] words = new String[3];
words[1] = "hello";
System.out.println(words[0].length());
}
}
A
NullPointerException
B
Compilation Error
C
No error, prints 0
D
ArrayIndexOutOfBoundsException
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | bommasam000 | 3 | 3 | 0m 33s | 267 |
| #2 | sathilak000 | 1 | 1 | 0m 10s | 90 |
| #3 | y.seong2027 | 1 | 1 | 0m 15s | 85 |
| #4 | suhanakochhar006 | 1 | 1 | 0m 23s | 77 |
| #5 | singhris000 | 1 | 1 | 0m 26s | 74 |
| #6 | sailajavadlamani33 | 1 | 1 | 0m 56s | 44 |
| #7 | geethasailaja | 1 | 4 | 9m 28s | -498 |
APFIVE