Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
medium Solved by 1 students

Java Array Null Pointer Exception

< Prev
Next >

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.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question
Mark for review

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|