Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 102

Given:

Your design requires that:

✑ fuelLevel of Engine must be greater than zero when the start() method is invoked.

✑ The code must terminate if fuelLevel of Engine is less than or equal to zero.

Which code fragment should be added at line n1 to express this invariant condition?

    Correct Answer: D

    To ensure the `fuelLevel` of `Engine` is greater than zero when the `start()` method is invoked, and terminate the program if the `fuelLevel` is less than or equal to zero, the correct code fragment to use is: `assert fuelLevel > 0: "Impossible fuel";`. This assertion verifies the condition `fuelLevel > 0` and, if the condition is false, an `AssertionError` is thrown with the specified message, fulfilling the requirement to terminate when `fuelLevel` is less than or equal to zero.

Discussion
maslacOption: D

Correct answer is D Condition must evaluate to false for execution of program to terminate

HanenBAOption: D

the correct code for assertion is assert (condition): "customized string message"; if condition is false then a runtime exception will be thrown with the customized string message correct answer is D

DarGrinOption: D

Correct answer D

steefaandOption: D

D is correct, as assert takes boolean (eliminating a) and it has to evaluate to false in order for Error to be thrown.

Eden0516Option: D

Correct answer is (D), tested