| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
easy Solved by 7 students
Checking for Null in an Array
< Prev
Next >

Which of the following conditions correctly checks that names[2] is not null?

public class ObjectArrayCheck {
    public static void main(String[] args) {
        String[] names = new String[3];
        names[0] = "Alice";
        names[1] = "Bob";
        // Missing line: Check whether names[2] is not null before attempting to print its length.
        if (names[2] != null) {
            System.out.println(names[2].length());
        }
    }
}
A

if (names[2] != null)

B

if (names[2] == null)

C

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

D

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

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
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
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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