Which statement, when inserted into the main()
method of a program, guarantees an AssertionError will be thrown at runtime?
D.
Unless assertions are enabled at runtime, no assertion statement guarantees an assertion will be thrown at runtime, making Option D the correct answer.
Next, Option A does not compile because the assert statement is not a method and does not take arguments in parentheses.
It's also invalid because it requires a boolean expression for the first expression, not a numeric one.
An additional value can be specified, but it requires a colon separator (:).
Option B would be the correct answer and trigger an error if assertions are enabled, since 0==1 evaluates to false.
Option C is incorrect.
Even if assertions were enabled, it would not trigger an error since 0==0 evaluates to true.