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(1)
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.
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.