Java Array Null Pointer Exception
Consider the following initializeNames method. What is a potential runtime error that can occur when this method is executed?
public class ObjectArrayExample {
public static void initializeNames(String[] names) {
for (int i = 0; i < names.length; i++) {
names[i].toUpperCase();
}
}
}
A
It incorrectly converts strings to uppercase by not assigning them back to the array.
B
It may throw a NullPointerException because the elements of the ‘names’ array are null by default.
C
There is no error; the method works as intended for object arrays.
D
It may lead to an ArrayIndexOutOfBoundsException due to improper loop boundaries.
Question Leaderboard
Not enough data yet to show leaderboard.
