| preferred AP College board partner for AP classes
AP Computer Science A/Unit 6: Array
Start Practice TestPractice Test
About Exam
easy Solved by 11 students
Conditional Array Element Assignment
< Prev
Next >

The following code segment is intended to assign the string “Welcome” to the first element of the messages array, but only if that element is currently null. Which of the following code fragments should replace /* missing code */ to correctly implement this logic?

public class InitializeObjectArray {
    public static void main(String[] args) {
        String[] messages = new String[3];
        /* missing code */
        System.out.println(messages[0]);
    }
}
A

messages[0].equals(“Welcome”);

B

if(messages[0] != null){ messages[0] = “Welcome”; }

C

messages[0] = new String(“Welcome”);

D

if(messages[0] == null){ messages[0] = “Welcome”; }

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
#1b.bao.o22 0m 00s 200
#2bommasam00033 2m 07s 173
#3singhris00011 0m 15s 85
#4sathilak00011 0m 17s 83
#5suhanakochhar00611 0m 39s 61
#6geethasailaja13 0m 52s 28
#7sailajavadlamani3312 2m 10s -40
#8y.seong202711 19m 36s -1,076
Items per page:
10
1 – 8 of 8
No comments yet. Be the first to comment!

AI Tutor

How can I help?

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