Welcome Guest | Sign in | Register
Flow Control - Discussion Page For Q.2799 | Java Programming Questions and Answers | Java Programming Free Online-Tests | LucentBlackBoard | LucentBlackBoard.com

Home > Java Programming > Flow Control > Questions and Answers

Q: 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 :-
A. int a = 3; 
short a = 4;
Boolean a = true;
B. char a = 'p'; 
short a = 4;
long a= 388;
C. char a = 'p';
int a = 3;
short a = 4;
D. long a= 388;
Boolean a = true;
short a = 4;

Answer and Explanation

Answer:char a = 'p';

int a = 3;
short a = 4;

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

Comment on this Question

Name:

Loading...




Partner Sites
LucentBlackBoard.com                  SoftLucent.com                  LucentJobs.com
All rights reserved © 2012-2015 SoftLucent.