Here are the proposed alternatives to be used in a method to return false if the object reference variable 'x' has the null value. Which statement will work?
Back to Questionsif( x == null ) return false ;
if( x.equals( null ) ) return false ;
if( x instanceof null ) return false ;
if( x eq null ) return false ;
Answer A is the only way to check a reference for the null value. <br/> <br/> Answer B is incorrect because if x is null, there will not be an object whose equals method can be called. This statement would cause a NullPointerException.<br/> <br/> Answer C is incorrect because only a reference type, such as a class, interface, or array, can be the right operand of the instanceof operator. <br/> <br/> D is invalid Java syntax