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

 
 

Share on Google+Share on Google+
SCJP Module-2 Question-9
Posted on: July 8, 2010 at 12:00 AM
Advertisement
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)

Advertisement

Related Tags for SCJP Module-2 Question-9:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: July 8, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com