Java OCA OCP Practice Question 400

Question

Which statement about if-then statements is true?

  • A. An if-then statement is required to have an else statement.
  • B. If the boolean test of an if-then statement evaluates to false, then the target clause of the if-then statement will still be evaluated.
  • C. An if-then statement is required to cast an object.
  • D. An if-then statement can execute a single statement or a block {}.


D.

Note

Option A is incorrect because else statements are entirely optional.

Option B is also incorrect.

The target of an if-then statement is not evaluated if the boolean test is false.

Option C is incorrect.

While an if-then statement is often used to test whether an object is of a particular type in order to cast it, it is not required to cast an object.

Option D is correct as an if-then statement may execute a single statement or a block of code {}.




PreviousNext

Related