What is the output of the following code?

Code:
public class ExamNameFinder {
public static String getExamName(String examId) {
String examName = null;
if (examId == null) {
return "ERROR";
}
switch (examId) {
case "1Z0-864": examName = "SCEA 5 Part 1";
break;
case "1Z0-804": examName = "OCP Java SE 7";
break;
case "1Z0-803": examName = "OCA Java SE 7";
break;
default: examName = "ERROR";
break;
}
return examName;
}
public static void main(String[] args) {
String examId = "1Z0-803";
String examName = ExamNameFinder.getExamName(examId);
System.out.println(examName);
}
}
public class ExamNameFinder {
public static String getExamName(String examId) {
String examName = null;
if (examId == null) {
return "ERROR";
}
switch (examId) {
case "1Z0-864": examName = "SCEA 5 Part 1";
break;
case "1Z0-804": examName = "OCP Java SE 7";
break;
case "1Z0-803": examName = "OCA Java SE 7";
break;
default: examName = "ERROR";
break;
}
return examName;
}
public static void main(String[] args) {
String examId = "1Z0-803";
String examName = ExamNameFinder.getExamName(examId);
System.out.println(examName);
}
}
Comments
I noticed your unanswered post so thought I would offer a reply.
Perhaps if you provided some context including your own thoughts to the problem, there would be more replies. Most forum members will not simply provide an answer to what appears to be a simple homework problem. Myself included.
Is there some aspect of the case statement that you don't understand?
Did you already attempt to byte-compile the code and run it through the java intepreter?
I hope this isn't an exhibit from a practice exam or ****. ("Moves finger towards big red button...")
Forum Admin at www.techexams.net
--
LinkedIn: www.linkedin.com/in/jamesdmurray
Twitter: www.twitter.com/jdmurray
Thanks for your tips Mr.Paul
Thanks Admin
here is the solution
A switch works with the byte, short, char, and int primitive data types. It also works with enumerated, the String class (introduced in Java SE 7), and a few special classes that wrap certain primitive types: Character, Byte, Short, and Integer. The String in the switch expression is compared with the expressions associated with each case label as if the String.equals method were being used.
So the Correct answer is OCA JAVA SE 7.
Thanks EPractize Labs Training Lab
My Friend Suggest me your tool.
I got the correct answer for my question from your trial version itself. Thanks
Good thing JD didnt have to use his big red button. I think it also launches the space shuttle and sets off all the car alarms within a 2 mile radius.
Forum Admin at www.techexams.net
--
LinkedIn: www.linkedin.com/in/jamesdmurray
Twitter: www.twitter.com/jdmurray