Java OCA OCP Practice Question 454

Question

Consider that str is a variable of class java.lang.String.

Which of the following lines of code may throw a NullPointerException in certain situations?

Select 3 options

  • A. if ( (str != null) | ( i == str.length () ) )
  • B. if ( (str == null) | ( i == str.length () ) )
  • C. if ( (str != null) || (i == str.length () ) )
  • D. if ( (str == null) || (i == str.length () ) )


Correct Options are  : A B C

Note

|| and && are short circuiting operation.

If the value of the expression can be known by just seeing the first part then the remaining part is not evaluated

while | and & will always let all the parts evaluates.




PreviousNext

Related