SCJP Module-2 Question-9

The program given below checks your understanding of switch in core Java and is also very useful for SCJP exam preparation.

 
 

Share on Google+Share on Google+

SCJP Module-2 Question-9

Ads

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)

Advertisements

Posted on: July 8, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles