LearnFrenzy
Sign in Take a free test

Control Flow Statements · Exercise 1 of 4

Control Flow Statements Control Flow MCQ

  • 20 questions
  • Page 1 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on Java control flow: if-else, classic switch and fall-through, switch expressions and yield, pattern matching switch, while, do-while, for, break, continue and labels. Pick an option to check your answer instantly.

Question 1 Easy

How many times, at minimum, does the body of a do-while loop run?

A 0
B 1
C 2
D It depends on the condition only
Question page & discussion
Question 2 Easy

Can the body of a while loop run zero times?

A No, never
B Yes, if the condition is false the first time it is checked
C Only with break
D Only inside a method
Question page & discussion
Question 3 Easy

In a classic switch, what happens when a case has no break?

A A compile error
B Execution continues into the next case's statements
C The switch restarts
D The default runs
Question page & discussion
Question 4 Medium

Which selector type is not allowed in a classic switch with constant case labels?

A String
B char
C long
D an enum
Question page & discussion
Question 5 Medium

What is yield used for?

A To pause a thread
B To return a value from a block arm of a switch expression
C To exit a loop
D To skip a case
Question page & discussion
Question 6 Medium

When can a switch expression over an enum omit default?

A Never
B When it has a case for every enum constant (it is exhaustive)
C Always
D Only for String switches
Question page & discussion
Question 7 Easy

Which is valid switch-expression syntax for "Saturday or Sunday"?

A case SAT || SUN ->
B case SAT, SUN ->
C case SAT: SUN ->
D case (SAT, SUN):
Question page & discussion
Question 8 Medium

In Java 21, what does case Integer i when i > 100 -> mean?

A It casts every value to Integer
B It matches only Integers greater than 100, binding the value to i
C when is a loop
D It is invalid syntax
Question page & discussion
Question 9 Medium

What happens when the selector of a classic switch (s) on a String is null?

A default runs
B NullPointerException
C The first case runs
D Nothing
Question page & discussion
Question 10 Medium

Which can be used as a classic case label?

A Any int variable
B A compile-time constant such as a literal or a static final constant
C A method call
D A random value
Question page & discussion

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links