Home Tutorial Java Scjp Part2 SCJP Module-2 Question-9

 
 

SCJP Module-2 Question-9
Posted on: July 8, 2010 at 12:00 AM
The program given below checks your understanding of switch in core Java and is also very useful for SCJP exam preparation.

What is the output of the following code :

public class Example9 {
public static void main(String[] args) {
System.out.println(check(1));
System.out.println(check(2));
System.out.println(check(3));
System.out.println(check(4));
}
static String check(int a) {
String alas = "?";
if (a < 3)
a--;
switch (a) {
case 1:
return "one";
case 2:
a = 3;
case 3:
break;
case 4:
default:
return alas;
}
return "Result" + a;
}

What is the output of the following code after compilation :

1. ?

2.  ? one Result 3

3.  ? one Result 3  ?

4.  compile error

Answer :

(3)

Related Tags for SCJP Module-2 Question-9:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.