Java OCA OCP Practice Question 476

Question

For a given non-null String myTestVariable, what is the resulting value of executing the statement myTestVariable.equals(null)?

  • A. true
  • B. false
  • C. The statement does not compile.
  • D. The statement compiles but will produce an exception when used at runtime.


B.

Note

The statement compiles and runs without issue, making Options C and D incorrect.

Since we are given that myTestVariable is not null, the statement will always evaluate to false, making Option B the correct answer.

If myTestVariable was null, then the code would still compile but throw a NullPointerException calling equals() at runtime.




PreviousNext

Related