Java Switch Case Interview MCQ Questions and Answers

0

Java Switch Case Interview MCQ Questions and Answers



1) A SWITCH case statement in Java is a ___ control statement.

A) Iteration

B) Loop

C) Selection

D) Jump

Answer [=]

C


2) Which is the alternative to SWITCH in Java language?

A) break, continue

B) for, while

C) if, else

D) goto, exit

Answer [=]

C

Explanation:

We can implement a SWITCH statement using IF, ELSE IF and ELSE control statements.

3) What are the keywords used to implement a SWITCH case in Java language?

A) switch, case

B) default

C) break

D) All

Answer [=]

D




4) What are the parts of a SWITCH in java?

A) switch input condition

B) case constants

C) case statements

D) All

Answer [=]

D




5) A SWITCH statement accepts ___ type of data as input.

A) byte

B) short

C) int

D) All

Answer [=]

D



6) A switch statement in Java accepts ___ as input data.

A) enum

B) String

C) enum and String

D) long

Answer [=]

C

Explanation:

SWITCH does not support long constants.




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 [=]  B

Explanation:  The semicolon (;) after SWITCH {} is not required. So option A is wrong though it compiles fine.




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 [=]  C





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 [=]  B

Explanation:   "break;" is optional.



 

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 [=]   B

Explanation:  DEFAULT statement alone can be written without any error.



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 [=]  D

Explanation: Case statements should start with either "case" or "default" only.




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 [=]D   Explanation:  case expressions must be constant expressions. So, make the variable final. 

final String college = "OXFORD";



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 [=]  B





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 [=]B

Explanation:It is allowed to write expressions that result in constant values.





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 [=]D

Explanation:Error: case expressions must be constant expressions So, make the variable final.

final int persons = 45;

//Then, output will be

CRICKET





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 [=] B

Explanation: Any expression that results in a Constant can be used as a "case constant".




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 [=]  B  



8) 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 [=] A




19) Does the following Java code-snippet compile?

switch(45)

{

case 10: ;

}

A) NO

B) YES

C) -

D) -

Answer [=]

B

Explanation:

You can specify dummy statements in java using a Semicolon (;).

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 [=]A

Explanation:This is the way we define ranges in a SWITCH construct.




21) Choose TRUE or FALSE. A SWITCH can be used to compare values for high or low.

A) FALSE

B) TRUE

C) -

D) -

Answer [=]A

Explanation:  More or Less conditions can not be checked with a SWITCH statement in Java.



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 [=]  A

Explanation:SWITCH case constants must be unique.




23) State TRUE or FALSE. SWITCH works faster than the IF-ELSE ladder in Java.

A) FALSE

B) TRUE

C) -

D) -

Answer [=]   B

Explanation: The compiler (JIT-Just In Time) creates a JUMP-TABLE for switch case branchings. So, it does not take time during Runtime. So, the SWITCH statement is fast.




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 [=]  D




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 [=] D

Explanation: Case constant 10 is duplicate. So, it causes compiler error.

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 [=] C

Explanation:"char" data type is allowed inside a Java SWITCH statement. The missing break statement causes CASE-C to be executed.



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 [=] A

Explanation:A SWITCH in java works well with enum constants. CASE Constants are defined without enum type.


java interview mcq questions and answers java interview mcq questions and answers for freshers java mcq interview questions and answers for experienced core java interview questions and answers mcq java mcq questions answers java interview questions answers what to ask in java interview java hands on interview questions java interview mcq questions and answers answers java interview mcq questions and answers audio java interview mcq questions and answers ap java interview mcq questions and answers and solutions pdf java interview mcq questions and answers and explanations java interview mcq questions and answers archive java interview mcq questions and answers act 1 java interview mcq questions and answers analyzing the text java interview mcq questions and answers accounting java interview mcq questions and answers array mcq java interview questions java quiz answers java basic interview questions and answers pdf mcq java questions and answers multiple choice java java interview mcq questions and answers biology java interview mcq questions and answers book java interview mcq questions and answers book pdf java interview mcq questions and answers bangla java interview mcq questions and answers by topic java interview mcq questions and answers by chapter java interview mcq questions and answers brain teasers java interview mcq questions and answers basic java interview mcq questions and answers boot java interview mcq questions and answers based behavioural interview questions and answers for java developer behavioral interview questions and answers for java developer core java interview multiple choice questions and answers for freshers java junior interview questions java interview mcq questions and answers download java interview mcq questions and answers doc java interview mcq questions and answers download pdf java interview mcq questions and answers doselect java interview mcq questions and answers dbms java interview mcq questions and answers dca java interview mcq questions and answers data structure java interview mcq questions and answers diploma pdf mcq for java interview java interview multiple choice questions and answers for experienced java objective type interview questions and answers for experienced java exp interview questions java ee interview questions for experienced java ee interview questions basic electronics mcq interview questions java fsd interview questions java interview mcq questions and answers github java interview mcq questions and answers general knowledge java interview mcq questions and answers grade 11 java interview mcq questions and answers general java interview mcq questions and answers grade 12 java interview mcq questions and answers grade 9 java interview mcq questions and answers game java interview mcq questions and answers geeksforgeeks java mcq questions and answers geeksforgeeks java mcq interview questions and answers java mcq questions geeksforgeeks java mcq interview questions and answers for freshers java interview mcq questions and answers hindi java interview mcq questions and answers high school java interview mcq questions and answers hindi pdf java interview mcq questions and answers html java interview mcq questions and answers hard java interview mcq questions and answers history java interview mcq questions and answers hackerearth java interview mcq questions and answers hackerrank java interview mcq questions and answers in hindi java interview mcq questions and answers in urdu java interview mcq questions and answers in tamil java interview mcq questions and answers in english java interview mcq questions and answers in pdf java interview mcq questions and answers in spanish java interview mcq questions and answers interview java interview mcq questions and answers infytq java interview mcq questions and answers indiabix java interview mcq questions and answers inheritance interview questions java coding java interview mcq questions and answers java java interview mcq questions and answers jmap java interview mcq questions and answers java pdf java interview mcq questions and answers jokes java interview mcq questions and answers job interview java interview mcq questions and answers javatpoint java interview mcq questions and answers javascript java interview mcq questions and answers jdbc java interview mcq questions and answers j2ee java interview mcq questions and answers job java interview mcq questions and answers khan academy java interview mcq questions and answers kenya java interview mcq questions and answers key java interview mcq questions and answers kjv java interview mcq questions and answers kingdom come questions java interview ikm java 8 test questions and answers download pdf java interview mcq questions and answers list java interview mcq questions and answers lahore java interview mcq questions and answers link java interview mcq questions and answers latest java interview mcq questions and answers language java interview mcq questions and answers linux java interview mcq questions and answers multiple choice java interview mcq questions and answers mp3 download java interview mcq questions and answers medium java interview mcq questions and answers math java interview mcq questions and answers movies java interview mcq questions and answers mettl java interview mcq questions and answers msbte java interview mcq questions and answers manual testing java interview mcq questions and answers mysql java interview mcq questions and answers multithreading java interview mcq questions and answers nz java interview mcq questions and answers number java interview mcq questions and answers nav java interview mcq questions and answers ng java interview mcq questions and answers no answers java interview mcq questions and answers ny java interview mcq questions and answers nj java interview mcq questions and answers networking java interview mcq questions and answers nursing java interview mcq questions and answers network programming java interview mcq questions and answers online java interview mcq questions and answers on answers java interview mcq questions and answers online pdf java interview mcq questions and answers on sponsorship java interview mcq questions and answers on home inspections java interview mcq questions and answers oops java interview mcq questions and answers on core java interview mcq questions and answers object oriented programming java interview mcq questions and answers object oriented programming using java interview mcq questions and answers operating system java interview mcq questions and answers pdf java interview mcq questions and answers pdf download java interview mcq questions and answers pdf free download java interview mcq questions and answers pdf msbte java interview mcq questions and answers programming java interview mcq questions and answers quizlet java interview mcq questions and answers questions java interview mcq questions and answers quora java interview mcq questions and answers question 2022 java interview mcq questions and answers quiz java interview mcq questions and answers reddit java interview mcq questions and answers registration java interview mcq questions and answers reading java interview mcq questions and answers registration form java interview mcq questions and answers registration 2022 java interview mcq questions and answers roblox java interview mcq questions and answers retail java interview mcq questions and answers sample java interview mcq questions and answers section 1 java interview mcq questions and answers sbi java interview mcq questions and answers sample pdf java interview mcq questions and answers strengths and weaknesses java interview mcq questions and answers scenarios java interview mcq questions and answers sanfoundry java interview mcq questions and answers swing java interview mcq questions and answers string java interview mcq questions and answers sql senior java developer interview questions and answers pdf java interview mcq questions and answers tamil java interview mcq questions and answers telegram java interview mcq questions and answers tcs java interview mcq questions and answers tamil pdf java interview mcq questions and answers tell me about yourself java interview mcq questions and answers today java interview mcq questions and answers trivia java interview mcq questions and answers topic wise java interview mcq questions and answers tutorial java interview mcq questions and answers tcs ira java interview mcq questions and answers using answers java interview mcq questions and answers urdu java interview mcq questions and answers uk java interview mcq questions and answers urdu pdf java interview mcq questions and answers using junior java developer interview questions and answers pdf java interview mcq questions and answers video java interview mcq questions and answers vidmate java interview mcq questions and answers variations java interview mcq questions and answers v13 java interview questions mcq with answers java interview mcq questions and answers xyz java interview mcq questions and answers x2 java interview mcq questions and answers xml x and y intercepts multiple choice questions java interview mcq questions and answers youtube java interview mcq questions and answers yt java interview mcq questions and answers yes or no java interview mcq questions and answers years experience java interview mcq questions and answers zambia java interview mcq questions and answers zimbabwe java interview questions quizlet java interview questions mid level java interview questions and answers for qa engineer java interview questions 2020 java interview mcq questions and answers 10th class java interview mcq questions and answers 10th grade java interview mcq questions and answers 10th java interview mcq questions and answers 11th grade java interview mcq questions and answers 12th 1000 interview questions and answers pdf java interview mcq questions and answers 2022 java interview mcq questions and answers 2021 java interview mcq questions and answers 2020 java interview mcq questions and answers 2018 java interview mcq questions and answers 2017 java interview mcq questions and answers 2016 java interview mcq questions and answers 3rd grade java interview mcq questions and answers 3rd java interview mcq questions and answers 3rd year java interview mcq questions and answers 3rd class java interview mcq questions and answers 3rd grade pdf java core interview questions and answers for experienced 3 questions to ask in a job interview java 4+ interview questions java 8 hands on interview questions the most common interview questions with 40+ sample answers java interview mcq questions and answers 5th grade java interview mcq questions and answers 5th java interview mcq questions and answers 5th grade pdf java interview mcq questions and answers 5th class java interview mcq questions and answers 50 questions java interview mcq questions and answers 5 years experience 5 questions interview 5 questions asked in an interview java interview mcq questions and answers 6th grade java interview mcq questions and answers 6th grade pdf java interview mcq questions and answers 6th java interview mcq questions and answers 6th class java interview mcq questions and answers 60's 6 interview questions java interview mcq questions and answers 7th grade java interview mcq questions and answers 7th java interview mcq questions and answers 7th grade pdf java interview mcq questions and answers 7th class 7 interview questions and answers chapter 7 java quizlet 7 interview questions java interview mcq questions and answers 8th grade java interview mcq questions and answers 8th java interview mcq questions and answers 8th grade pdf java interview mcq questions and answers 8th class java interview mcq questions and answers 8 coding java multi choice questions interview questions java 8 java interview mcq questions and answers 9th grade java interview mcq questions and answers 9th java interview mcq questions and answers 9th class java interview mcq questions and answers 9th grade pdf java interview mcq questions and answers 9th pdf 9 interview questions
Java Switch Case Interview MCQ Questions and Answers


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 [=] B

Explanation:Apple and APPLE are different strings.

Post a Comment

0 Comments
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !