Java OCA OCP Practice Question 255

Question

Which lines check that x is equal to four?

Assume assertions are enabled at compile time and runtime.

  • A. assert x == 4;
  • B. assert x != 4;
  • C. assert x == 4 : "x is not 4";
  • D. assert x != 4 : "x is not 4";


A, C.

Note

The boolean that follows the assert keyword is the condition that must be met.

The condition may optionally be followed by a colon, followed by a message that is displayed if the assertion fails.




PreviousNext

Related