exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 154 discussion

Actual exam question from Oracle's 1z0-808
Question #: 154
Topic #: 1
[All 1z0-808 Questions]

Given the code fragment:

What is the result?

  • A. A B
  • B. A element 0 B element 1
  • C. A NullPointerException is thrown at runtime.
  • D. A 0 B 1
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
iSnover
Highly Voted 10 months ago
Selected Answer: A
The right answer is the letter A, remember that String is immutable, the "concat" method inside the for each as it didn't receive a variable wasn't storing anything, so it didn't change. And then at the time of printing, it printed A B because nothing has changed. NOTE: To concatenate a String variable, it would have to be -> | strs[idx] = strs[idx] + " element " + idx; | Instead of what's in the code.
upvoted 5 times
...
Rajeevkuamr
Most Recent 6 months, 4 weeks ago
Answer is A. A B
upvoted 1 times
...
akbiyik
8 months ago
Selected Answer: A
Answer is A.
upvoted 1 times
...
carloswork
9 months, 2 weeks ago
Selected Answer: A
Answer is A. To test: public static void main(String[] args) { String[] strs = {"A", "B"}; int idx = 0; for(String s : strs) { strs[idx].concat(" element " + idx); idx++; } for(idx = 0; idx < strs.length; idx++) { System.out.println(strs[idx]); } }
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago