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