Correct. Answer is C.
In the first 'for', when trying to execute n.substring for the name "Peter", an exception will be thrown. So in the catch block it will print "Invalid Name", in the second 'for' it will print "omas" and the default values of the remaining elements of the pwd array.
It can be tested, iSnover give the source code below.
Correnct is C, there are no comments to make. If you want to test the code:
public class Main {
public static void main(String[] args) {
String names [] = {"Thomas", "Peter", "Joseph"};
String pwd [] = new String [3];
int idx = 0;
try {
for (String n: names) {
pwd [idx] = n.substring(2, 6);
idx++;
}
}
catch (Exception e) {
System.out.println ("Invalid Name");
}
for (String p: pwd) {
System.out.println (p);
}
}
}
upvoted 3 times
...
This section is not available anymore. Please use the main Exam Page.1z0-808 Exam Questions
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.
somrita90
10 months, 1 week agoyanoolthecool
6 months, 3 weeks agoVicky_65
1 year, 2 months agocarloswork
1 year, 8 months agoiSnover
1 year, 9 months ago