exam questions

Exam 1z0-808 All Questions

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

Exam 1z0-808 topic 1 question 52 discussion

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

Given the code fragment:

What is the result?

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

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
Saftschnitzel
Highly Voted 4 years, 8 months ago
To add to the explanation: The JVM throws a null pointer exception because a method (concat()) is called on an object containing null. Note that the print() method does not cause JVM to throw an exception and prints null.
upvoted 23 times
...
letmein2
Highly Voted 5 years, 5 months ago
correct. null pointer is thrown at the line strs[idx].concat("element" + idx); because strs[0] is null.
upvoted 6 times
...
vic88
Most Recent 5 days, 16 hours ago
Selected Answer: D
D is right. During each iteration: First iteration (idx = 0): strs[0] is null. strs[idx].concat(" element " + idx) attempts to call concat on null, which leads to a NullPointerException.
upvoted 1 times
...
Vicky_65
1 year, 8 months ago
Selected Answer: D
D is correct
upvoted 1 times
...
odzio33
1 year, 11 months ago
Selected Answer: D
String[] strings = new String[2]; int idx = 0; for(String s : strings){ strings[idx].concat(" element " + idx); idx++; } for (idx = 0; idx < strings.length; idx++){ System.out.println(strings[idx]); } Exception in thread "main" java.lang.NullPointerException
upvoted 1 times
...
akbiyik
2 years ago
NullPointerException is thrown at runtime.
upvoted 1 times
...
tawa_z58
2 years ago
D is correct .NullPointerException is thrown at runtime .
upvoted 1 times
...
v323rs
4 years, 11 months ago
Correct D. A NullPointerException is thrown at runtime.
upvoted 3 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