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
easy Solved by 4 students

Checking for Null in an Array

Mark
< Prev
Next >

Consider the following code segment.

String[] names = new String[3];
names[0] = "Alice";
names[1] = "Bob";

if (/* condition */) {
    System.out.println(names[2].length());
}

Which of the following expressions should replace /* condition */ to ensure that a NullPointerException is not thrown when the code is executed?

A

if (names[2].length() > 0)

B

if (names[2] == null)

C

if (names[2] != null)

D

if (names[2].equals(null))

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total Time
Score
#1y.seong202711 0m 06s 94
#2sailajavadlamani3311 1m 03s 37
#3bommasam00025 2m 18s 32
#4sssemihunal01 0m 01s -11
Items per page:
10
1 – 4 of 4

AI Tutor

How can I help?

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