Test Series - java

Test Number 33/64

Q: A SWITCH case statement in Java is a ___ control statement.
A. Iteration
B. Loop
C. Selection
D. Jump
Solution: no solution
Q: Which is the alternative to SWITCH in Java language?
A. break, continue
B. for, while
C. if, else
D. goto, exit
Solution: We can implement a SWITCH statement using IF, ELSE IF and ELSE control statements.
Q: What are the keywords used to implement a SWITCH case in Java language?
A. switch, case
B. default
C. break
D. All
Solution: no solution
Q: What are the parts of a SWITCH in java?
A. switch input condition
B. case constants
C. case statements
D. All
Solution: no solution
Q: A SWITCH statement accepts ___ type of data as input.
A.  byte
B. short
C. int
D. All
Solution: no solution
Q: A switch statement in Java accepts ___ as input data.
A. enum
B. String
C. enum and String
D. long
Solution: SWITCH does not support long constants.
Q: Choose the correct syntax of SWITCH statement in Java below.
A. switch(input) { case constant1: //statements; break; case constant2: //statements; break; default: //statements; };
B. switch(input) { case constant1: //statements; break; case constant2: //statements; break; default: //statements; }
C. switch(input) { case constant1: //statements; break; case constant2: //statements; break; default case: //statements; };
D. switch(input) { case constant1: //statements; break; case constant2: //statements; break; default case: //statements; }
Solution: The semicolon (;) after SWITCH {} is not required. So option A is wrong though it compiles fine.
Q: Which version of Java did start supporting String as the input data type of a SWITCH?
A. JDK 5
B. JDK 6
C. JDK 7
D. JDK 8
Solution: no solution
Q: What is the output of Java program with SWITCH below?
int a=10;
switch(a)
{
case 10: System.out.println("TEN");
}
A. No output
B. TEN
C. Compiler error as there is no BREAK.
D. None
Solution: "break;" is optional.
Q: What is the output of the Java program below?
int b=20;
switch(b)
{
default: System.out.println("LION");
}
A. No output
B. LION
C. Compiler error as there are no CASE statements.
D. None
Solution: DEFAULT statement alone can be written without any error.

You Have Score    /10