Java Switch Case Interview MCQ Questions and Answers

Study and learn Interview MCQ Questions and Answers on Java Switch Case Statements. Attend job interviews easily with these Multiple Choice Questions. You can print these Questions in default mode to conduct exams directly. You can download these MCQs in PDF format by Choosing Print Option first and Save as PDF option next using any Web Browser.

Go through Java Theory Notes Switch Case before reading these objective questions.



1) A SWITCH case statement in Java is a ___ control statement.
A) Iteration
B) Loop
C) Selection
D) Jump
Answer [=]
Answer[=]
2) Which is the alternative to SWITCH in Java language?
A) break, continue
B) for, while
C) if, else
D) goto, exit
Answer [=]
Answer[=]
3) What are the keywords used to implement a SWITCH case in Java language?
A) switch, case
B) default
C) break
D) All
Answer [=]
Answer[=]
4) What are the parts of a SWITCH in java?
A) switch input condition
B) case constants
C) case statements
D) All
Answer [=]
Answer[=]
5) A SWITCH statement accepts ___ type of data as input.
A) byte
B) short
C) int
D) All
Answer [=]
Answer[=]
6) A switch statement in Java accepts ___ as input data.
A) enum
B) String
C) enum and String
D) long
Answer [=]
Answer[=]
7) 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;
}
Answer [=]
Answer[=]


 

8) 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
Answer [=]
Answer[=]
9) 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
Answer [=]
Answer[=]
10) 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
Answer [=]
Answer[=]
11) What is the output of the Java program below?
String animal = "GOAT";
switch(animal)
{
  break: System.out.println("DOMESTIC");
}
A) No output
B) GOAT
C) DOMESTIC
D) Compiler error
Answer [=]
Answer[=]
12) What is the output of the Java program below?
String college = "OXFORD";
switch("STANFORD")
{
case college: System.out.println("EXAM TIME"); break;
default: System.out.println("UNKNOWN");
}
A) EXAM TIME
B) UNKNOWN
C) STANFORD
D) Compiler error
Answer [=]
Answer[=]
13) What is the output of Java program with SWITCH?
int num=20;
switch(num)
{
case 10: System.out.println("TEN"); break;
case 20: System.out.println("TWENTY"); break;
case 30: System.out.println("THIRTY");
}
A) TEN
B) TWENTY
C) THIRTY
D) TEN TWENTY
Answer [=]
Answer[=]
14) What is the output of Java program below?
int num=40;
switch(num)
{
case 5: System.out.println("FIVE"); break;
case 35+5: System.out.println("FORTY"); break;
case 20+30: System.out.println("FIFTY");
}
A) FIVE
B) FORTY
C) FIFTY
D) Compiler error
Answer [=]
Answer[=]


 

15) What is the output of the below Java program?
int persons = 45;
int random = 45;
switch(random)
{
  case persons: System.out.print("CRICKET ");
  default: System.out.println("RUGBY");
}
A) CRICKET
B) CRICKET RUGBY
C) RUGBY
D) Compiler error
Answer [=]
Answer[=]
16) What is the output of the below Java program?
switch(15)
{
  case 5*2: System.out.println("TEN");break;
  case 5*4-5:System.out.println("FIFTEEN");break;
  case 60/4+5: System.out.println("TWENTY");
}
A) TEN
B) FIFTEEN
C) TWENTY
D) Compiler error
Answer [=]
Answer[=]
17) A SWITCH fall through occurs in Java only in the absence of ___.
A) case keyword
B) break keyword
C) default keyword
D) None
Answer [=]
Answer[=]
18) What is the purpose of designing a SWITCH logic with a fall-through in Java?
A) To define ranges.
B) To define additions
C) To improve switch block performance
D) None
Answer [=]
Answer[=]
19) Does the following Java code-snippet compile?
switch(45)
{
  case 10: ;
}
A) NO
B) YES
C) -
D) -
Answer [=]
Answer[=]
20) What is the output of the below Java program with a SWITCH statement?
int points=6;
switch(points)
{
  case 6: ;
  case 7: System.out.println("PASS");break;
  case 8: ;
  case 9: System.out.println("Excellent");break;
  case 10: System.out.println("Outstanding"); break;
  default: System.out.println("FAIL");
}
A) PASS
B) Excellent
C) Outstanding
D) FAIL
Answer [=]
Answer[=]
21) Choose TRUE or FALSE. A SWITCH can be used to compare values for high or low.
A) FALSE
B) TRUE
C) -
D) -
Answer [=]
Answer[=]


 

22) State TRUE or FALSE. It is allowed to use duplicate case constants inside a Java SWITCH statement.
A) FALSE
B) TRUE
C) -
D) -
Answer [=]
Answer[=]
23) State TRUE or FALSE. SWITCH works faster than the IF-ELSE ladder in Java.
A) FALSE
B) TRUE
C) -
D) -
Answer [=]
Answer[=]
24) Choose the correct statement about Java SWITCH statements.
A) A SWITCH can contain another SWITCH statement.
B) Switch case statements are allowed inside IF-ELSE ladders.
C) Switch statements are allowed inside Loops like for, while and do while.
D) All
Answer [=]
Answer[=]
25) What is the output of the below Java program?
int hours = 10;
switch(hours)
{
  case 10: System.out.println("TEN");break;
  case 10: System.out.println("TEN AGAIN"); break;
  default: System.out.println("TEN AS USUAL");
}
A) TEN
B) TEN AGAIN
C) TEN AS USUAL
D) Compiler error
Answer [=]
Answer[=]
26) What is the output of the below Java program?
char grade = 'B';
switch(grade)
{
  case 'A': System.out.print("GRADE-A ");break;
  case 'B': System.out.print("GRADE-B ");
  case 'C': System.out.print("GRADE-C ");
}
A) GRADE-A
B) GRADE-B
C) GRADE-B GRADE-C
D) Compiler error
Answer [=]
Answer[=]
27) What is the output of the below Java program with SWICH and ENUM?
static enum ANIMAL {GOAT, TIGER, CAMEL}
public static void main(String args[])
{
  ANIMAL ani = ANIMAL.CAMEL;
  switch(ani)
  {
    case GOAT: System.out.println("GOAT");break;
    case CAMEL: System.out.println("CAMEL");break;
    case TIGER: System.out.println("TIGER");break;
  }

}
A) CAMEL
B) GOAT
C) TIGER
D) Compiler error
Answer [=]
Answer[=]
28) What is the output of the below Java program with SWITCH and Strings?
String phone = "APPLE";
switch(phone)
{
case "Apple": System.out.println("Apple");break;
case "APPLE": System.out.println("APPLE");break;
case "SAMSUNG": System.out.println("SAMSUNG");
}
A) Apple
B) APPLE
C) SAMSUNG
D) Compiler error
Answer [=]
Answer[=]


Like or Share

Show some care. Like or Subscribe. [FB]...[Youtube]

C MCQ App by ExamTray 

Android APP

Java MCQ App by ExamTray 

Android APP
ALL MCQ App by ExamTray Android APP

Ad

 

Try Some Java Books

Book Price
1. Java - The Complete Reference  Check Price
2. Core Java: An Integrated Approach, Black Book Check Price
3. Java All-in-One for Dummies Check Price
4. OCP Java SE 8: Programmer II Check Price
5. Programming with Java Check Price
6. Head First Java Check Price

We may get some affiliate commission for the above purchases.