SCJP Module-2 Question-1
The given program will help in understating of switch in java and it is also useful for SCJP.
The given program will help in understating of switch in java and it is also useful for SCJP.
Find the missing snippet in the below code :
1. public class Test {
2. public static void main(String [ ] args) {
3.
4. switch(a) {
5. default:
6. System.out.println("You choose correct option");
7. } } }
Which given below snippet is best for inserting at line number 3 to compile the
above code successfully :-
(1)int a = 3;
(2)short a = 4;
(3)char a = 'p';
(4)long a= 388;
(5)Boolean a = true;
Answer :
(1) ,(2) &(3)
Explanation :
Because in this code switch() method only allows integer ,short , character
and enum constants as argument. The "long" data type & "Boolean" is not
permissible as argument to 'switch()'.