Consider the following lines of code...
System.out.println(null + true); //1
System.out.println(true + null); //2
System.out.println(null + null); //3
Which of the following statements are correct?
comp.lang.javascript FAQ: http://jibbering.com/faq/
SCJP 1.4, SCWCD, SCBCD 1.3
If only one operand expression is of type String, then string conversion is performed on the other operand to produce a string at run time.
Enthuware - Best Mock Exams and Questions for Oracle Java Certifications
Quality Guaranteed - Pass or Full Refund!
http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#40220
"...
If only one operand expression is of type String, then string conversion is performed on the other operand to produce a string at run time. The result is a reference to a newly created String object that is the concatenation of the two operand strings. The characters of the left-hand operand precede the characters of the right-hand operand in the newly created string.
. . .
"The + operator is syntactically left-associative, no matter whether it is later determined by type analysis to represent string concatenation or addition. In some cases care is required to get the desired result. For example, the expression:
a + b + c
is always regarded as meaning:
(a + b) + c
Therefore the result of the expression:
1 + 2 + " fiddlers"
is:
"3 fiddlers"
..."
There is a string conversion to type String from every other type, including the null type.
comp.lang.javascript FAQ: http://jibbering.com/faq/
comp.lang.javascript FAQ: http://jibbering.com/faq/
comp.lang.javascript FAQ: http://jibbering.com/faq/