Author name: admin

Which loop construct guarantees that the loop body is executed at least once?

Java MCQ: Which loop construct guarantees that the loop body is executed at least once? a) for loop b) while loop c) do-while loop d) continue statement Answer: c) do-while loop Explanation: The do-while loop in Java guarantees that the loop body is executed at least once, regardless of the condition. This is because the

Which loop construct guarantees that the loop body is executed at least once? Read More »

What is the key difference between a while loop and a do-while loop in Java?

Java MCQ: What is the key difference between a while loop and a do-while loop in Java? a) The syntax used to define the loop b) The number of iterations performed c) The condition check timing d) The ability to use the break statement Answer: c) The condition check timing Explanation: The key difference between

What is the key difference between a while loop and a do-while loop in Java? Read More »

Which loop construct in Java is best suited when the number of iterations is unknown?

Java MCQ: Which loop construct in Java is best suited when the number of iterations is unknown? a) for loop b) while loop c) do-while loop d) none Answer: b) while loop Explanation: The while loop in Java is best suited for scenarios where the number of iterations is unknown or depends on a certain

Which loop construct in Java is best suited when the number of iterations is unknown? Read More »

Which loop construct in Java is best suited when the number of iterations is known?

Java MCQ: Which loop construct in Java is best suited when the number of iterations is known? a) for loop b) while loop c) do-while loop d) break statement Answer: a) for loop Explanation: The for loop in Java is best suited when the number of iterations is known beforehand. This loop is ideal for

Which loop construct in Java is best suited when the number of iterations is known? Read More »

Which method is used to assert that a condition is true in JUnit?

Java MCQ: Which method is used to assert that a condition is true in JUnit? a) assertTrue() b) assertCondition() c) assertMatch() d) assertEquals() Answer: a) assertTrue() Explanation: The assertTrue() method is used in JUnit to assert that a condition is true. If the condition is true, the test passes; if it is false, the test

Which method is used to assert that a condition is true in JUnit? Read More »

Which annotation is used to run a method once before all tests in JUnit 5?

Java MCQ: Which annotation is used to run a method once before all tests in JUnit 5? a) @BeforeTest b) @BeforeClass c) @BeforeAll d) @SetupAll Answer: c) @BeforeAll Explanation: The @BeforeAll annotation in JUnit 5 is used to run a method once before all tests in the test class. This is useful for performing time-consuming

Which annotation is used to run a method once before all tests in JUnit 5? Read More »

Which assertion is used to check that two values are equal in JUnit?

Java MCQ: Which assertion is used to check that two values are equal in JUnit? a) assertSame() b) assertEqual() c) assertEquals() d) assertMatch() Answer: c) assertEquals() Explanation: The assertEquals() assertion is used in JUnit to check that two values are equal. This assertion compares the expected value with the actual value and passes the test

Which assertion is used to check that two values are equal in JUnit? Read More »

Scroll to Top