Share on Google+Share on Google+

SCJP Module-2 Question-1

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) {
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()'.


Posted on: July 6, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null