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.
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.
Correct
D. A NullPointerException is thrown at runtime.
upvoted 3 times
...
Log in to ExamTopics
Sign in:
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.
Saftschnitzel
Highly Voted 4 years, 8 months agoletmein2
Highly Voted 5 years, 5 months agovic88
Most Recent 5 days, 16 hours agoVicky_65
1 year, 8 months agoodzio33
1 year, 11 months agoakbiyik
2 years agotawa_z58
2 years agov323rs
4 years, 11 months ago