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

 
 

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

Advertisement

Related Tags for SCJP Module-2 Question-1:


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.

Posted on: July 6, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com