250+ TOP MCQs on Control Statements – 2 and Answers

This set of Java Multiple Choice Questions & Answers (MCQs) on “Control Statements”.

1. What would be the output of the following code snippet if variable a=10?

  1. if(a<=0)
  2. {
  3.    if(a==0)
  4.    {
  5.      System.out.println("1 ");
  6.    }
  7.    else 
  8.    { 
  9.       System.out.println("2 ");
  10.    }
  11. }
  12. System.out.println("3 ");

a) 1 2
b) 2 3
c) 1 3
d) 3

Answer: d
Clarification: Since the first if condition is not met, control would not go inside if statement and hence only statement after the entire if block will be executed.

2. The while loop repeats a set of code while the condition is not met?
a) True
b) False

Answer: b
Clarification: While loop repeats a set of code only until the condition is met.

3. What is true about a break?
a) Break stops the execution of entire program
b) Break halts the execution and forces the control out of the loop
c) Break forces the control out of the loop and starts the execution of next iteration
d) Break halts the execution of the loop for certain time frame

Answer: b
Clarification: Break halts the execution and forces the control out of the loop.

4. What is true about do statement?
a) do statement executes the code of a loop at least once
b) do statement does not get execute if condition is not matched in the first iteration
c) do statement checks the condition at the beginning of the loop
d) do statement executes the code more than once always

Answer: a
Clarification: Do statement checks the condition at the end of the loop. Hence, code gets executed at least once.

5. Which of the following is used with the switch statement?
a) Continue
b) Exit
c) break
d) do

Answer: c
Clarification: Break is used with a switch statement to shift control out of switch.

6. What is the valid data type for variable “a” to print “Hello World”?

  1. switch(a)
  2. {
  3.    System.out.println("Hello World");
  4. }

a) int and float
b) byte and short
c) char and long
d) byte and char

Answer: d
Clarification: The switch condition would only meet if variable “a” is of type byte or char.

7. Which of the following is not a decision making statement?
a) if
b) if-else
c) switch
d) do-while

Answer: d
Clarification: do-while is an iteration statement. Others are decision making statements.

8. Which of the following is not a valid jump statement?
a) break
b) goto
c) continue
d) return

Answer: b
Clarification: break, continue and return transfer control to another part of the program and returns back to caller after execution. However, goto is marked as not used in Java.

9. From where break statement causes an exit?
a) Only from innermost loop
b) Terminates a program
c) Only from innermost switch
d) From innermost loops or switches

Answer: d
Clarification: The break statement causes an exit from innermost loop or switch.

10. Which of the following is not a valid flow control statement?
a) exit()
b) break
c) continue
d) return

Answer: a
Clarification: exit() is not a flow control statement in Java. exit() terminates the currently running JVM.

Leave a Reply

Your email address will not be published. Required fields are marked *