Q. - Given the code fragment:-
5. int color;
6. char colorCode = 'b';
7. switch (colorCode) {
8. case 'r':
9. color = 100;
10. break;
11. case 'b':
12. color = 10;
13. break;
14. case 'y':
15. color= 1;
16. break;
17. }
18. System.out.println(color);
What is the result?
A) It results in a compile time error at line 18.
B) It results in a compile time error at line 9.
C) It prints: 1
D) It prints: 10
⧪ please give your answer in a comment section.
5. int color;
6. char colorCode = 'b';
7. switch (colorCode) {
8. case 'r':
9. color = 100;
10. break;
11. case 'b':
12. color = 10;
13. break;
14. case 'y':
15. color= 1;
16. break;
17. }
18. System.out.println(color);
What is the result?
A) It results in a compile time error at line 18.
B) It results in a compile time error at line 9.
C) It prints: 1
D) It prints: 10
⧪ please give your answer in a comment section.
2 Comments
D
ReplyDeleteA, since int color; not initialised. we have to initialize the local variables.
ReplyDelete