Question ID :958011966030 Consider the following lines of code... System.out.println(null + true); //1 System.out.println(true + null); //2 System.out.println(null + null); //3 1. None of the 3 lines will compile 2. Compiles and prints nulltrue, truenull and nullnull respectively 3. line 1 and 2 won't compile, but line 3 will print nullnull 4. line 3 won't compile but line1 and 2 will print nulltrue and truenull 5. None of the above. The answer says 1 but it compiles fine on my jdk1.3
A value x of primitive type T is first converted to a reference value as if by giving it as an argument to an appropriate class instance creation expression: If T is boolean, then use new Boolean(x). If T is char, then use new Character(x). If T is byte, short, or int, then use new Integer(x). If T is long, then use new Long(x). If T is float, then use new Float(x). If T is double, then use new Double(x). This reference value is then converted to type String by string conversion. Now only reference values need to be considered. If the reference is null, it is converted to the string "null" (four ASCII characters n, u, l, l). Otherwise, the conversion is performed as if by an invocation of the toString method of the referenced object with no arguments; but if the result of invoking the toString method is null, then the string "null" is used instead.
[ February 28, 2002: Message edited by: Valentin Crettaz ]
I tried this piece of code on my JDK1.2, it gave compile errors: cannot convert null or boolean to int. I guess JDK 1.3 has a different implementation on this. Should we follow JDK1.3 as the correct answer? Well, I guess I need to update my compiler now.
Rob/Valentin/Others could you please confirm this for JDK 1.2 i.e. Java 2. I have JDK 1.3.1 and am not sure if I will be able to download 1.2 today or not. Is it a compile time error or not? Thanks, Brian
Joined: Feb 18, 2002
Brian, I tried it. Others please confirm since Brian does not believe me. JDK afetr 1.2 should all be called Java 2, I think. I think they should not give this kind of conflicting questions on the real exam.
Originally posted by Brian Lugo: Rob/Valentin/Others could you please confirm this for JDK 1.2 i.e. Java 2. I have JDK 1.3.1 and am not sure if I will be able to download 1.2 today or not. Is it a compile time error or not? Thanks, Brian
[ March 01, 2002: Message edited by: Holmes Wong ]
Joined: Nov 10, 2000
Sorry Holmes I did not notice your reply. I was in the POST reply mode and had that window open for a while, in the mean time you had already posted. I am taking your word ...
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com