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?
a) None of the 3 lines will compile
b) All the 3 line will compile and print nulltrue, truenull and nullnull respectively
c) line 1 and 2 won't compile but line 3 will print nullnull
d) line 3 won't compile but line 1 and 2 will print nulltrue and truenull respectively
e) none of the above.
And the answer is.... hmmm... don't know!
The answer said option "A" was correct, but I run this code and get option "B".
the explanation for this answer (option A) is:
... None of the parameters is a String so conversion to String will not happen. It will try to convert everything to an int and you will get:
Incompatible type for +. Can't convert null to int.
But my compiler didn't complain at all!
P.S. Taken from JQPlus.
[ July 07, 2003: Message edited by: Andres Gonzalez ]
[ July 07, 2003: Message edited by: Andres Gonzalez ]