Fill-in-the-Blank Quiz
1. The simplest form of a conditional statement in Java is the ______ statement.
a) if
b) switch
c) for
d) while
2. The ______ operator is a shorthand for the if-else statement in Java.
a) Logical
b) Relational
c) Ternary
d) Arithmetic
3. The ______ loop ensures that the loop body is executed at least once, regardless of the
condition.
a) for
b) while
c) do-while
d) enhanced for
4. In a switch statement, if no case matches, the ______ block is executed.
a) break
b) default
c) continue
d) else
5. The ______ array allows the inner arrays to have different lengths.
a) Multidimensional
b) Jagged
c) Two-dimensional
d) Nested
6. To avoid deeply nested if statements, it is recommended to use ______ operators to
simplify conditions.
a) Logical
b) Bitwise
c) Assignment
d) Unary
7. In a for loop, the ______ part is executed after each iteration.
a) Condition
b) Initialization
c) Update
d) Declaration
8. The JOptionPane class is part of the ______ package in Java.
a) java.io
b) javax.swing
c) java.util
d) java.awt
9. A method declared with the ______ keyword belongs to the class rather than an instance
of the class.
a) final
b) static
c) abstract
d) public
10. The ______ loop is suitable for iterating over arrays or collections without using an index
variable.
a) for
b) while
c) enhanced for
d) do-while
Fill-in-the-Blank Quiz
1. Conditional statements in Java control the ______ of execution.
a) syntax
b) flow
c) variables
d) operators
2. The ______ statement provides an alternative path if the condition is false.
a) if
b) else
c) if-else
d) switch
3. The ______ ladder is used for multiple conditions checked sequentially.
a) if-else
b) if-else-if
c) switch
d) nested if
4. The ______ statement is an alternative to multiple if-else statements when checking specific
values.
a) switch
b) ternary
c) while
d) nested if
5. A ______ is an assignment operator, while == is a comparison operator.
a) =
b) ==
c) !=
d) ===
6. The three parts of a for loop are initialization, ______, and update.
a) declaration
b) condition
c) iteration
d) increment
7. The do-while loop executes the loop body at least ______.
a) once
b) twice
c) thrice
d) never
8. A two-dimensional array is also called a ______.
a) list
b) grid
c) matrix
d) cube
9. The ______ array is a multidimensional array where inner arrays can have different lengths.
a) jagged
b) nested
c) simple
d) grid
10. The size of an array in Java is ______ after it is declared.
a) dynamic
b) fixed
c) variable
d) flexible
11. Methods improve code ______ by encapsulating commonly used logic.
a) readability
b) reusability
c) redundancy
d) performance
12. A ______ method belongs to the class and can be called without creating an object.
a) static
b) instance
c) abstract
d) overloaded
13. Method ______ allows multiple methods to have the same name with different parameter
lists.
a) overriding
b) overloading
c) encapsulation
d) polymorphism
14. The ______ keyword is used to declare static methods in Java.
a) final
b) public
c) abstract
d) static
15. The JOptionPane class is commonly used for ______ dialogs in Java.
a) graphical
b) terminal-based
c) console
d) popup
16. The JOptionPane.showMessageDialog() method is used to display ______ to the user.
a) input
b) warnings
c) errors
d) messages
17. A ______ dialog asks the user for Yes/No/Cancel responses.
a) confirm
b) input
c) option
d) message
18. The JOptionPane.showInputDialog() method prompts the user for ______.
a) confirmation
b) messages
c) input
d) options
19. A ______ dialog offers multiple buttons for user selection.
a) confirm
b) message
c) option
d) custom
20. Java provides three main types of loops: for, while, and ______.
a) do-while
b) foreach
c) repeat
d) nested
21. The ______ operator is used for logical NOT in Java.
a) !
b) ||
c) &&
d) ==
22. A nested if statement allows ______ conditions to be checked.
a) independent
b) multiple
c) complex
d) invalid
23. The ______ method is called when an object is instantiated.
a) instance
b) overloaded
c) constructor
d) static
24. A multidimensional array is useful for storing ______ data.
a) one-dimensional
b) grid-like
c) non-tabular
d) abstract
25. Loops are used for reducing ______ in programs.
a) conditions
b) variables
c) repetition
d) errors
26. The ______ loop is best for iterating through arrays or collections.
a) while
For loop yan
b) do-while
c) enhanced for
d) switch
27. The ______ statement terminates the loop execution prematurely.
a) break
b) continue
c) exit
d) stop
28. The ______ keyword skips the current iteration of a loop.
a) exit
b) break
c) continue
d) return
29. ______ arrays allow inner arrays to have varying lengths.
a) Jagged
b) Simple
c) Fixed
d) Nested
30. The JOptionPane.showConfirmDialog() method returns an integer representing the user's
______.
a) message
b) action
c) response
d) input
31. The default case in a switch statement is executed if ______ case matches.
a) every
b) no
c) at least one
d) all
32. The term "constructor" refers to a special ______ method in Java.
a) overloaded
b) static
c) initialization
d) runtime
33. A ______ is a set of instructions grouped together to perform a specific task.
a) constructor
b) method
c) loop
d) statement
34. The ternary operator uses ______ and ______ symbols.
a) &&, ||
b) =, ==
c) ?, :
d) %, &
35. Java’s ______ array can be visualized as a cube.
a) three-dimensional
b) two-dimensional
c) jagged
d) static
36. The JOptionPane.QUESTION_MESSAGE displays a dialog with a ______ icon.
a) warning
b) question
c) error
d) plain
37. Java developers use loops to handle ______ inputs until a condition is met.
a) multiple
b) invalid
c) dynamic
d) repetitive
38. The JOptionPane class is part of the ______ package.
a) javax.swing
b) java.util
c) java.io
d) java.lang
39. ______ is one of the most common uses for multidimensional arrays in Java.
a) String manipulation
b) Matrix operations
c) Conditional checks
d) File handling
40. A ______ operator combines multiple conditions in an if statement.
a) relational
b) logical
c) bitwise
d) ternary
41. The ______ of an array is fixed at declaration time.
a) size
b) length
c) scope
d) reference
42. A ______ method does not return a value in Java.
a) void
b) static
c) overloaded
d) constructor
43. The ______ loop is often used when the number of iterations is unknown beforehand.
a) while
b) for
c) enhanced for
d) do-while
44. The JOptionPane.ERROR_MESSAGE is used to display ______.
a) success messages
b) information
c) errors
d) options
45. Java’s if-else statements are best for handling ______ outcomes.
a) single
b) binary
c) sequential
d) repetitive
46. Arrays in Java are zero-______ by default.
a) incremented
b) based
c) indexed
d) aligned
47. Nested loops are useful for working with ______ data structures.
a) simple
b) linear
c) multidimensional
d) one-dimensional
48. The ______ operator is commonly used for decision-making in a single line.
a) ternary
b) bitwise
c) assignment
d) relational
49. To avoid errors, always check for ______ conditions in if-else statements.
a) unreachable
b) edge
c) dynamic
d) nested
50. A switch statement is often preferred over if-else statements for handling ______ cases.
a) sequential
b) numeric
c) fixed
d) specific