|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
Do you have paypal account? Click Here to pay now and get the questions.
|
|
SCJP 5.0 Objective - 2(10 Questions)
1) What will be the output of the following program?
package chapters.chap02;
public class Chap02 {
public static void main(String[] args) {
for (int i=0; i<5; i++){
switch (i){
case 0:
System.out.println("0");
++i;
break;
case -1:
System.out.println("-1");
break;
case 2:
System.out.println("2");
i++;
case 4:
System.out.println("4");
break;
}
}
}
}
- The program will not stop and it will run recursively upon execution
- The program will output '0 2 5 5'.
- The program will output '0 2 4 4'.
- The program will output '02 4 5'.
Answer
1) c
Answer c is correct. Upon execution the variable 'i' will have a value of 0 which matches the first case, 0 is printed and the value of 'i' is incremented to 1. Because of the break statement, the control comes out of the switch block, and now the value of 'i' is increased to 2 in the for loop. After printing 2, the value of 'i' is incremented to 3, and in the for loop, the value of 'i' happens to be 4 and subsequently the values 4 and 4 gets printed.
|
|
350 Mock Questions on SCJP 1.5 - JUST Rs.200 or 7 USD
Send us mail to sales@javabeat.net
more details
|
|