Hi all. I took a stab at question 9 on page 503 of K&B SCJP 5 book. I guessed incorrectly and noticed that one of the correct answers is G. I dont really understand what is happening here. I would have imagined that the Integer object would be unboxed to an int... Can someone be so kind as to elaborate on why G. is a correct answer? Thank you & regards.
G is correct because when you pass new Long("123"), System.out.format evaluates new Long("123").toString()
Remember: %s if argument is null, result is null. if argument is a primitive type , result=primitive if argument is a string, result=string if argument is an object, result=object.toString().
SCJP 5, SCWCD 5
Joined: May 06, 2008
Thanks for that concise answer Antonio. Much appreciated.
Originally posted by Noam Wolf: Hi Keith, can you please provide the question and possible answers? I don't have a copy of the book handy.
Sorry Noam, but Im not going to post copyrighted material in the forums. If you haven't already bought the book, you should, if you can. Check out Amazon. It's a great book and would definitely benefit you in your studies. best regards & good luck.
The general policy at the ranch is that it's okay to post mock exam questions as long as you cite the source of the question. So in this case it would have been fine to say: "Here's a question from K&B..."
It's also fine to quote small sections from books. I'd say that most authors are really happy if you're discussing their books, as long as you got your copy legally
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Joined: May 06, 2008
Duly noted Bert. Thanks for a great publication and keep up the good work! best regards. K
Here's the pertinent question Noam, from the K&B SCJP 5 book: Which will compile and run without Exception? (Choose all that apply.) A. System.out.format("%b", 123); B. System.out.format("%c", "x"); C. System.out.printf("%d", 123); D. System.out.printf("%f", 123); E. System.out.printf("%d", 123.45); F. System.out.printf("%f", 123.45); G. System.out.format("%s", new Long("123")); [ June 22, 2008: Message edited by: Keith Nagle ]