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

 
 

Share on Google+Share on Google+
SCJP Module-2 Question-19
Posted on: July 8, 2010 at 12:00 AM
Advertisement
The program given below check your knowledge of core flow control of core Java and also very useful in preparation of SCJP examination.

What will be the output of the following block of code: 

public class Example19{
static int a = 7;

public static void main(String[] args) {
String str = "";
for (int b = 0; b < 3; b++) {
a++;
switch (a) {
case 8:
str += "8 ";
case 9:
str += "9 ";
case 10: {
str += "10 ";
break;
}
default:
str += "d ";
case 13:
str += "13 ";
}
}
System.out.println(s);
}

static {
a++;
}
}

What will be the output of the following block of code: 

1.   9 10 10 d 13

2.   d 13 10  9 10

3.   10 10 9 d 13

4.   9 10 10 13 d

Answer :

(1)

Explanation :

Firstly, the static block will execute & increment the value of  After it, At first iteration of the loop ,the  output will be 9 10. And at second iteration ,the output will be 10 & At last iteration ,the output will be d,13.

Advertisement

Related Tags for SCJP Module-2 Question-19:


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