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

 
 

SCJP Module-2 Question-1
Posted on: July 6, 2010 at 12:00 AM
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()'.

Related Tags for SCJP Module-2 Question-1:


Ask Questions?

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.