| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
Share
About Exam
medium Solved by 4 students
Java Array Null Pointer Exception
< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy